Back Up Sript

Topics: File system, Batch file, 4DOS Pages: 5 (1317 words) Published: December 5, 2012
Sometimes it is useful, or even necessary to simply copy existing directories to another hard disk or network drive, rather than using more complicated backup methods. Multiple directories can be backed up comparatively easy with a simple click, by creating and running a batch file. That file can be executed manually from your desktop, can be added to startup or scheduled for periodic execution as needed.  Batch files have comparatively easy syntax and can have many uses, so this method could also be a good learning experience by example. You can simply copy the text below, and paste it into Notepad. Create a new file with either .bat or .cmd extension, rather than txt. Here is a working example of a backup script you can modify for your needs: @echo off

:: variables
set drive=G:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents" echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"
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 email and contacts (MS Outlook)...

%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook" echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg" regedit /e "%drive%\Registry\regbackup.reg"
:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..." echo Backup Complete!
 The above example backs up "My Documents", Favorites, Outlook Express email/address book, (all for the current user) and the Windows Registry. It copies the files to the directory defined in the %drive% variable, or "g:\Backup". If the script is ran multiple times, it will only rewrite if the source files are newer. It will create subdirectories as necessary, and it will retain file attributes. It can copy system and hidden files. In the above file, all lines that begin with "::" are comments. The "set drive=" and "set backupcmd=" near the top define two variables (referenced by %drive% and %backupcmd%), used a number of times throughout the file; the first being the location of the top directory where we want to backup, and the second the actual copy command with all necessary switches. All the "echo " lines in the file simpy output the line of text to the screen, and the lines beginning with %backupcmd% are the actual commands to execute. Note that most of the folders in the above backup example are subdirectories of the %USERPROFILE%... It is possible to simply backup the entire user profile with My Documents, Favorites, Outlook Express, Outlook, etc. by backing up this one folder. Here is an example (it assumes the above "drive" and "backupcmd" variables are set): %backupcmd% "%USERPROFILE%" "%drive%\%UserName% - profile"

Backing up Other Directories and networked PCs
You can backup other directories by simply creating more alike lines: %backupcmd% "...source dir..." "%drive%\...destination dir..." For example, if you'd like to backup "C:\Program Files\Microsoft Office"  to our destination "G:\Backup\MS Office" (and retain the directory structure) you'd need to add the following line to the batch file: %backupcmd% "C:\Program Files\Microsoft Office" "%drive%\MS Office" Here is another example, backing up the Administrator Profile on a machine on the LAN with computer name "Lianli": %backupcmd% "\\Lianli\c\Documents and Settings\Administrator"  "%drive%\Lianli - admin profile" Remember, you have to save the batch file with either .bat or .cmd extension, then just double-click to execute it.  Using the Current Date

Sometimes it is...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Back Up and Recovery Policy Essay
  • Back to school Essay
  • Take A Step Back And LISTEN UP Essay
  • Back Then Essay
  • Essay on The Importance of Law (Legal Back Up) to an Individual, Organization and Economy of a Country at Large
  • Back to Representation Essay
  • Essay about There And Back Again
  • Back Titration Essay

Become a StudyMode Member

Sign Up - It's Free