Results 1 to 3 of 3

Thread: Need help with batch file backup tool

  1. #1
    Senior Member watercooled's Avatar
    Join Date
    Jan 2009
    Posts
    11,478
    Thanks
    1,541
    Thanked
    1,029 times in 872 posts

    Need help with batch file backup tool

    I've made a batch file to backup certain folders to a USB device. This is what I have so far:
    @echo off
    :: variables
    set drive=F:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"
    set backupcmd=xcopy /s /c /e /h /i /y

    echo ### Backing up My Documents...
    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents\"

    echo ### Backing up Firefox...
    %backupcmd% "%USERPROFILE%\Application Data\Mozilla" "%drive%\Mozilla\"

    echo ### Backing up Thunderbird
    %backupcmd% "%USERPROFILE%\Application Data\Thunderbird" "%drive%\Thunderbird\"

    echo ### Backing up Desktop
    %backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop\"

    echo Backup Complete!
    @pause
    Currently, it backs up to a folder called Backup followed by a dated folder on drive F. I know there is a way to prompt for a drive using the /p command but I've not used prompts like this before. How can I prompt for a drive letter and still output a folder called Backup followed by the date?
    For example driveletter\Backup\Date
    Thanks

  2. #2
    blueball
    Guest

    Re: Need help with batch file backup tool

    If your batch file was called saveme.bat you could enter the following to run it:

    saveme g

    Which would tell it to backup to drive G

    In your batch file you would change it as follows:

    @echo off

    if %1 == "" goto OOPS
    Goto RUNME

    :OOPS
    echo You must supply a drive letter to backup to eg saveme g
    goto END

    :RUNME


    :: variables
    set drive=%1:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"
    set backupcmd=xcopy /s /c /e /h /i /y

    echo ### Backing up My Documents...
    %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents\"

    echo ### Backing up Firefox...
    %backupcmd% "%USERPROFILE%\Application Data\Mozilla" "%drive%\Mozilla\"

    echo ### Backing up Thunderbird
    %backupcmd% "%USERPROFILE%\Application Data\Thunderbird" "%drive%\Thunderbird\"

    echo ### Backing up Desktop
    %backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop\"

    echo Backup Complete!
    @pause
    :END
    @echo on

  3. Received thanks from:

    watercooled (26-05-2009)

  4. #3
    Senior Member
    Join Date
    Aug 2008
    Posts
    492
    Thanks
    8
    Thanked
    106 times in 80 posts

    Re: Need help with batch file backup tool

    Wouldn't it be simpler to pass the drive letter to the script as an argument?

    eg:

    set drive=%1:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"


    Then you could just run the command "Mybackup.bat F" where F (or whatever) is the drive letter...

    edit: far, far too slow...

    Quote Originally Posted by blueball View Post
    if %1 == "" goto OOPS
    Slight correction (sorry) - %1 needs to be in quotes: if "%1" == "" goto OOPS
    ...
    Last edited by CaptainCrash; 25-05-2009 at 08:40 PM.

  5. Received thanks from:

    watercooled (26-05-2009)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Execute batch file during login
    By DataMatrix in forum Help! Quick Relief From Tech Headaches
    Replies: 9
    Last Post: 16-01-2008, 04:57 PM
  2. Network Storage Device
    By Whatsthisdo in forum Networking and Broadband
    Replies: 31
    Last Post: 14-11-2007, 03:37 AM
  3. PHP and file uploads timing out too soon
    By McClane in forum Software
    Replies: 12
    Last Post: 02-12-2006, 05:57 PM
  4. Replies: 45
    Last Post: 09-01-2006, 01:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •