Jump to content

Recommended Posts

@echo off
:: variables
set drive=C:\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!
@pause
cls
%backupcmd% "%USERPROFILE%" "%drive%\%UserName% - profile"
@pause

Rate This Plz

Used in Windows Batch File .bat

Edited by nmedovich
Link to comment
Share on other sites


The main problems are:

  • You should be using SETLOCAL in order to ensure that variables are local only to the running batch file.
  • Your XCOPY switches are not really very intelligently used.

Other than that because there is little happening, there isn't much else to improve upon; there is no need to created FOR loops but you could tidy it slightly:

@ECHO OFF&SETLOCAL

SET "L_=D:\Backup"
SET "M_=Copying"
SET "S_=%USERPROFILE%"
SET "C_=XCOPY/DEIQRVY"

SET "D_=My Documents"
ECHO/ %M_% %D_%...
%C_% "%S_%\%D_%" "%L_%\%D_%"

SET "D_=Favorites"
ECHO/ %M_% %D_%...
%C_% "%S_%\%D_%" "%L_%\%D_%"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...