CastleCops, Internet Crime Fighters
Need help? Click here to register for free! Absolutely zero advertisements on this site!

Donation/Premium
spacer
block bottom
Security Central
spacer
· Home
· PIRT/Fried Phish
· MIRT
· SIRT
· Deutsch
· Wiki
· Newsletter
· O16/ActiveX
· CLSID List
· Contest2007
· Downloads
· Feedback (send)
· Forums
· HijackThis
· Hijacktrend
· LSPs
· My Downloads
· O18
· O20
· O21
· O22
· O23
· O9
· Premium
· Private Messages
· Proxomitron
· Reviews
· Search
· StartupList
· Stories Archive
· Submit News
· WsIRT
· Your Account
· Acceptable Use Policy
block bottom
spacer spacer

Backing up using a batch file?

 
Post new topic   Reply to topic       All -> FavForums -> Software [del.icio.us!] [digg it!] [reddit!]
View previous topic :: View next topic  
Author Message
GregorBerry

Trooper
Trooper


Joined: Dec 30, 2004
Posts: 33
Location: UK

PostPosted: Wed Jul 09, 2008 12:15 pm    Post subject: Backing up using a batch file?
Reply with quote

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
View users profile Send private message
Mister2

SRT Team Lead
SRT Team Lead
Premium Member

Joined: Oct 28, 2004
Posts: 7326

Moderators MVP Premium SRT Team F@H

PostPosted: Wed Jul 09, 2008 1:34 pm    Post subject:
Reply with quote

Hi GregorBerry,

Ah, the good old days of DOS! Laughing

Copy the text in the box below into Notepad, go to File, Save, change the file type to All Files and Save as MyBackup.bat (or whatever you want to call it with the .bat extension) to your desktop.

Code:
xcopy /m /e /y "%userprofile%\My Documents\*.*" e:\Backup\
pause


I have assumed you will backup to a folder named Backup on your external drive. Change this to whatever you like, but if more than 8 characters or if it contains a space then enclose it in double quotes - "e:\My Backup Files\"

The first time you run the program it will probably copy all the contents of your My Documents folder. Subsequent runs will copy only changed files.

/m specifies only files that have changed
/e makes sure subdirectories are included
/y suppresses the prompt to overwrite an older file

That is how I used to copy files over from an old laptop at work and it did the trick. Smile


_________________
Never stop learning
Back to top
View users profile Send private message
k027

Special Response Team
Guest Forums Host
Guest Forums Host

Joined: Aug 25, 2003
Posts: 8479

1st Responders SRT

PostPosted: Wed Jul 09, 2008 1:40 pm    Post subject:
Reply with quote

Quote:
I'm not familiar with batch file syntax


See this:

http://www.computerhope.com/batch.htm

Back to top
View users profile Send private message
GregorBerry

Trooper
Trooper


Joined: Dec 30, 2004
Posts: 33
Location: UK

PostPosted: Wed Jul 09, 2008 5:35 pm    Post subject:
Reply with quote

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
View users profile Send private message
PapaDos

Lieutenant
Lieutenant
Premium Member

Joined: Mar 20, 2004
Posts: 224
Location: Canada
Premium

PostPosted: Wed Jul 09, 2008 10:58 pm    Post subject:
Reply with quote

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
View users profile Send private message
GregorBerry

Trooper
Trooper


Joined: Dec 30, 2004
Posts: 33
Location: UK

PostPosted: Thu Jul 10, 2008 11:36 am    Post subject:
Reply with quote

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
View users profile Send private message
Display posts from previous:   
Post new topic   Reply to topic       All -> FavForums -> Software All times are GMT
Page 1 of 1

 
Quick Reply:
Username: 

Quote the last message
Attach signature (signatures can be changed in profile)
 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001 phpBB Group
spacer spacer