| View previous topic :: View next topic |
| Author |
Message |
GregorBerry
Trooper

 Joined: Dec 30, 2004 Posts: 33 Location: UK
|
Posted: Wed Jul 09, 2008 12:15 pm Post subject: Backing up using a batch file? |
|
|
I've been looking for a way to back up files which have been altered since my last backup to my external hard drive for a while, and came across the suggestion of using a batch file. I found the following sample code:
| Quote: | | "backup.bat" @echo off set drive=e:\Backup set backupcmd=xcopy /s /c /d /e /h /i /r /k /y echo ### Backing up My Documents... %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents" echo Backup Complete! @pause |
I'm not familiar with batch file syntax, and obviously I need to customize the above code to suit my specific needs. Could someone give me some help doing this?
Apologies if this isn't the right forum for this, but it was the closest fit I could find.
|
|
| Back to top |
|
 |
Mister2
SRT Team Lead
 Premium Member
 Joined: Oct 28, 2004 Posts: 7326
|
|
| Back to top |
|
 |
k027
Special Response Team Guest Forums Host

 Joined: Aug 25, 2003 Posts: 8479
|
|
| Back to top |
|
 |
GregorBerry
Trooper

 Joined: Dec 30, 2004 Posts: 33 Location: UK
|
Posted: Wed Jul 09, 2008 5:35 pm Post subject: |
|
|
Thank you both very much for the replies.
Mister2 - with the help of your reply and a few related things I managed to find, I created the following batch file:
| Quote: | @echo off
set drive="F:\My PC Backup"
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"
echo ### Backing up Firefox Profiles...
%backupcmd% "%USERPROFILE%\Application Data\Mozilla\Firefox" "%drive%\Firefox"
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"
echo ### Backing up email and address book (Outlook Express)...
%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"
echo ### Backing up Start Menu...
%backupcmd% "%USERPROFILE%\Start Menu" "%drive%\Start Menu"
%backupcmd% "C:\Documents and Settings\All Users\Start Menu" "%drive%\Start Menu"
echo Backup Complete!
@pause |
A bit of testing reveals a slight problem with this. It works perfectly, provided that in the second line the variable 'drive' has no spaces in it. So, for example,
| Quote: | | set drive="F:\Backup" |
works, but
| Quote: | | set drive="F:\My PC Backup" |
does not, even though the path is in double quotes. Can you see where the problem is?
|
|
| Back to top |
|
 |
PapaDos
Lieutenant
 Premium Member
 Joined: Mar 20, 2004 Posts: 224 Location: Canada
|
Posted: Wed Jul 09, 2008 10:58 pm Post subject: |
|
|
Don't use quotes in your SET command...
And be careful not to put any spaces at the end of the line... _________________ Festina Lente
|
|
| Back to top |
|
 |
GregorBerry
Trooper

 Joined: Dec 30, 2004 Posts: 33 Location: UK
|
Posted: Thu Jul 10, 2008 11:36 am Post subject: |
|
|
Thanks, works perfectly now! Should save me a lot of time compared with doing things manually as I have been.
Just one final issue. Files which have been deleted from my C drive or even renamed will presumably still be present on my F drive. Is there any easy way to sort this out, other than to periodically delete my backup folder and start fresh?
|
|
| Back to top |
|
 |
|
|