Windows batch backup file (code included for you!)

Discussion in 'OT Technology' started by Swift, May 13, 2007.

  1. Swift


    Apr 22, 2007
    Likes Received:

    So I wrote a backup script (with some help from Google) and modified it for my own use, so I can backup my computer with it daily (using Windows scheduler). I'm having a problem, if it gets to a file (mainly the database file for a program named My Notes Keeper) the DOS backup window will close and the backup will not continue, anyone know how I can modify it so it will copy all files regardless of it being in use? Thanks. Enjoy the code below, and please let me know if you know how to fix my problem. :hsd:

    (Note: Just copy the code into a file named backup.bat and then change the paths below, and drive letters to your backup drive and it should be good to go).

    for /f "tokens=1-4 delims=/ " %%g in ('date /t') do (
    set mm=%%g
    set dd=%%h
    set yy=%%i

    echo #Backing up: Outlook
    mkdir "e:\~backup\%mm%-%dd%-%yy%\Owner\Outlook"
    xcopy "C:\Users\Owner\AppData\Local\Microsoft\Outlook" "e:\~backup\%mm%-%dd%-%yy%\Owner\Outlook" /s /i

    echo #Backing up: Desktop
    mkdir "e:\~backup\%mm%-%dd%-%yy%\Owner\Desktop"
    xcopy "C:\Users\Owner\Desktop" "e:\~backup\%mm%-%dd%-%yy%\Owner\Desktop" /s /i

    echo #Backing up: Documents
    mkdir "e:\~backup\%mm%-%dd%-%yy%\Owner\Documents"
    xcopy "C:\Users\Owner\Documents" "e:\~backup\%mm%-%dd%-%yy%\Owner\Documents" /s /i
  2. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Mar 14, 2000
    Likes Received:
    Vancouver, BC, CANADA

    Why are you not using the built in backup program? Secondly, Backup Exec (which is really what the built-in backup program is but watered down) comes with an add-on function that allows open files to be backed up. I doubt you can do this easily without some kind of agent or the use of Shadow Copies (W2K3). You might also want to look at Robocopy for these types of things.

    What you can do though is shutdown the service, back up the file and then restart it. That will ensure the file is closed.
  3. deusexaethera

    deusexaethera OT Supporter

    Jan 27, 2005
    Likes Received:
    I believe you're looking for the "/q" tag. This tag puts the copy function into Quiet mode, which means it will try, fail, and move on if it hits a file it can't copy.

    When you're done playing with this, check out SyncToy from Microsoft. It does what you want, looks pretty, and takes less effort.

Share This Page