A way to backup your files (Windows XP)

Backing up files is a vital part of using IT. Unfortunately, backing up files is boring and potentially time consuming. This solution was arrived at after evaluating about 4-5 freeware, shareware and commercial alternatives.

Criteria

  • Low cost
  • Can handle backup over the network
  • Automatic operation
  • Email notification of success or failure
  • Set and forget

Components

The backup solution uses:

  • ntbackup – the free backup solution provided with win XP
  • a .bat (or batch) file
  • the Windows scheduler
  • Blat command line mailer (http://www.blat.net/)

Solution

The key to the solution is the following .bat file. It is pretty much self documenting. The batch file is called either:

For full backup

backup.bat normal

For differential backup

backup.bat differential

Text of backup.bat

setlocal

REM
REM Assumptions
REM – blat is installed and available
REM you have created an ntbackup saved selections file for your selections .bks
REM

REM 041002 drp start
if “%1″==”normal” goto parm1ok
if “%1″==”differential” goto parm1ok

:parm1notok
cls
echo Parm1 is not “normal” or “differential”

goto eof

:parm1ok

REM 041002 drp end

REM
REM START OF CONFIGURATION
REM

set backupcomputername=%computername%
set backupusername=%username%

REM enter here the backup destination
set backupdestunc=\\MACHINENAME\backupshare

REM enter here a free alias for accessing the backup drive
set backupdestdrvalias=z:

REM enter here the location of this .bat file. Standard location is in a directory called backup under
REM your ‘my documents’ folder
REM if you have moved my documents to a nonstandard location you will need to change this line otherwise OK.
set backuphome=%userprofile%My Documentsbackup

REM this is pretty standard but you may have to change it
set ntbackupexehome=%windir%system32

REM the following directory is the place where ntbackup puts it’s log files. You find them on this computer
REM but viewing a log within NTBACKUP then doing a File Save As in notepad and seeing what directory the file was in.
set ntbackuplogshome=%USERPROFILE%Application DataMicrosoftWindows NTNTBackupdata

set ntbackupfileselectionname=mydocuments

REM do include the .bks in the next line
set ntbackupfileselection=%backuphome%%ntbackupfileselectionname%.bks
if not exist “%ntbackupfileselection%” goto noselection

REM include the .bkf in the next line
if “%1” == “normal” set backupfilename=%backupdestdrvalias%backups%backupcomputername% %backupusername% %ntbackupfileselectionname% %random%.bkf
if “%1” == “differential” set backupfilename=%backupdestdrvalias%backups%backupcomputername% %backupusername% %ntbackupfileselectionname% lastdiff.bkf

set backupnotifyemailaddress=yourname@yourdomain.com

REM
REM END OF CONFIGURATION
REM

net use %backupdestdrvalias% /d
net use %backupdestdrvalias% “%backupdestunc%”

“%ntbackupexehome%ntbackup.exe” backup “@%ntbackupfileselection%” /v:no /r:no /rs:no /hc:off /m %1 /j “%backupfilename%” /l:s /f “%backupfilename%”

REM Find and include the log(s) since last email to send
md “%backuphome%logs”
del “%backuphome%logs*.log”

xcopy “%ntbackuplogshome%*.log” “%backuphome%logs” /M
copy “%backuphome%logs*.log” “%backuphome%howdiditgo.txt” /y

net use %backupdestdrvalias% /d

:notify
REM de-unicodeify the logs
type “%backuphome%howdiditgo.txt” > “%backuphome%howdiditgonounicode.txt”
blat “%backuphome%howdiditgonounicode.txt” -subject “SmelovaBackup – %backupcomputername% %backupusername% %ntbackupfileselectionname% %1 may have completed Backup” -to %backupnotifyemailaddress%

goto eof

:noselection
echo NO SELECTION FILE %ntbackupfileselection%
goto eof

:eof
REM pause