Batch File Automatic backup

Discussion in 'Software' started by nubbles, Jul 22, 2010.

  1. nubbles

    nubbles Private E-2

    Alright.. Well I've been racking my brain with this all morning. Here is what I need to do:

    Preferably by batch file I need to back up files that are client specific. For example:

    At the end of the day, run the batch file that scans a folder containing all the logs, finds which ones are there and moves them to their appropriate folder in another directory.

    EG:


    1. Scan folder \Logs\
    2. Finds "1.log;3.log" etc.
    3. Moves them to C:\Log\1 and C:\Log\3 respectively.

    I hope there is an easy way to do this.. I don't want to be writing thousands of lines to copy files that probably aren't even there on other days.

    If I'm being vague, I will include more information.
     
  2. PC-XT

    PC-XT Master Sergeant

    Just a quick one, though I'm not sure it's what you want:
    Code:
    @echo off
    cd Logs
    if exist "1.log" move "1.log" c:\log\1\1.log /y
    if exist "2.log" move "2.log" c:\log\2\2.log /y
    if exist "3.log" move "3.log" c:\log\3\3.log /y
    
    It overwrites the old logs, which I'm not sure you want. You can add more logs to move with copy/paste, and changing the 4 numbers to whatever name you want. Or do you want something that makes folders for new logs, and both moves and renames them to avoid overwriting, without having to edit the batch file? I think that's possible, though I don't have time to write it now. There are more than a few people here who can write better batch files than me, though.
     
  3. nubbles

    nubbles Private E-2

    THank you. This will do. The only problem is that the files also have timestamps in their names:

    EG: 1_00000.log

    Is the above command adaptive to wildcards and how can I copy it, preserving the file name?
     
  4. nubbles

    nubbles Private E-2

    Nevermind, cheated :D
     
  5. GermanOne

    GermanOne Guest

    If you want to move all found .log files you could use this:

    Code:
    @echo off &setlocal
    
    :: source root folder
    set source=C:\whereever\logs
    
    :: destination root folder
    set destn=C:\log
    
    md "%destn%" 2>nul
    pushd "%source%" ||goto :eof
    for /f "delims=" %%a in ('dir /a-d /b *.log') do (
      md "%destn%\%%~na" 2>nul
      move /y "%%~a" "%destn%\%%~na\"
    )
    popd
    
    
    Regards
    GermanOne
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds