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
    10,879
    Thanks
    1,503
    Thanked
    936 times in 806 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
    Account closed at user request
    Join Date
    Aug 2005
    Location
    Edinburgh
    Posts
    2,427
    Thanks
    846
    Thanked
    379 times in 294 posts
    • blueball's system
      • Motherboard:
      • Gigabyte Z270 - HD3P
      • CPU:
      • i7-7700K (4 x 4.2GHz plus HT)
      • Memory:
      • Team Group Vulcan T-Force 32GB (2x16GB) DDR4 PC4-19200C14 2400MHz
      • Storage:
      • 1TB Samsung 960 EVO NVMe PCIE M.2 plus Samsung 860 EVO 4TB SSD
      • Graphics card(s):
      • ASUS RTX 2080 Ti ROG Strix OC
      • PSU:
      • Corsair HX850 850 W Full Modular 80 Plus Platinum
      • Case:
      • Corsair Carbide 330R Ultra Silent Midi Tower
      • Operating System:
      • Win 7 Ultimate x64 (using wufuc to allow Win7 to run on this CPU)
      • Monitor(s):
      • BenQ GW2765HT LED IPS 27 inch 2560x1440
      • Internet:
      • Virgin Media 380Mb

    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
  •