Automating Windows Backups for Workstations
Today I wrote a small Windows command line script for automating
Windows backups on ordinary workstations (My Documents folder, Outlook
PST files and several application directories).
The script runs fully automatic and is therefore very user-friendly because
the technical barrier for making backups on workstations must be as low
as possible, otherwise no backups are made (this is my experience). The script
is also capable of copying files from remote computers to back them up on a
local CD burning device.
So here we go.
Assumptions:
I assume that the destination folder for the temporary backup files and the
directory where all the tools needed reside is "
C:\Backup".
I also assume that you run Windows XP (because of the "
rd" command (older versions of Windows don't have this command,
but you can use deltree instead).
Installation of the tools:
First of all you need some parts of the
UnxUtils package. For this script we only need "
tar.exe". If you want to compress the generated tar file
you will also need either gzip or bzip or some other compression utility.
The reason why I create a tar file to be saved on disc is because of the long
filenames that may occure on Windows systems (more than the ISO9660 standard
would allow).
The next thing we need is the
cdrtools package for Windows. From this package we need "
cdrecord" and "
mkisofs".
Discover the CD burning device
To discover the CD burning device for cdrecord, use the following command:
cdrecord -scanbus
Which produces an output like:
0,0,0 0) 'SEAGATE ' 'ST318453LW ' '0003' Disk
0,1,0 1) *
0,2,0 2) 'TEAC ' 'CD-ROM CD-532S ' '1.0A' Removable CD-ROM
0,3,0 3) *
0,4,0 4) *
0,5,0 5) *
0,6,0 6) *
0,7,0 7) *
In this case, your CD burning device would be "
0,2,0".
The directory structure:
If you did everything right, you should have a directory structure like this one
listed here:
Directory C:\BACKUP
12.01.2006 11:57 <DIR> .
12.01.2006 11:57 <DIR> ..
12.01.2006 10:43 1.655 awbfw.cmd
17.05.2005 15:16 314.368 cdrecord.exe
03.07.2005 02:30 1.295.582 cygwin1.dll
17.05.2005 15:16 421.376 mkisofs.exe
11.11.2001 00:00 114.688 tar.exe
The script:
Please keep in mind that the synthetic linebreaks (\ at the end of a line, etc.)
are not functional in Windows command line scripts. I just put them in here
so that the Code-Block doesn't get to wide.
@echo off
rem Automatic Windows Backup Script for Workstations
rem
rem This script tars the files to be backup'ed together into one archive,
rem creates an ISO-image of the tar-archive and burns it onto a CD with the
rem help of cdrecord
rem
rem (c) 2006 by Alexander Griesser <work@tuxx-home.at>
rem Get the current date
set TODAY=%DATE:~0%
rem ============================ CONFIGURATION ========================
rem Specify an Identifier for this Backup
set ITEM=Tagname
rem The Backup-Root directory (the necessary tools also have to reside here)
set BACKUP_ROOT=C:\Backup
rem Path to the logfile
set LOGFILE=%BACKUP_ROOT%\Backup-%ITEM%.log
rem cdrecords burning device identifier (use cdrecord -scanbus to get
rem that info)
set CDDEVICE=2,0,0
rem Activate this setting if you need to copy files from another
rem computer in your network to this computer
rem set BACKUP_DIR=%BACKUP_ROOT%\%ITEM%
rem ===================================================================
echo Automatic Windows Backup for Workstations
echo
echo Please ensure that the CD burner is connected to your PC and
echo that a CD is inserted and press Enter when ready.
pause
rem Activate this command to copy files from another computer to this
rem machine for backup (you will need the robocopy utility from the
rem Microsoft Windows Ressource Kit for this - or any other utility
rem that does the trick)
rem echo Copying files from remote computer(s)...
rem %BACKUP_ROOT%\robocopy.exe \\otherpc\C$\application \
%BACKUP_DIR%\application /E /R:5 /W:5 /LOG:%LOGFILE%
rem Creation of the backup archive by either using local folders (for backing
rem up this computer) or by using %BACKUP_DIR% as source (when copying files
rem from remote computers)
echo Creating Backup Archive...
%BACKUP_ROOT%\tar.exe -cf %BACKUP_ROOT%\%ITEM%-%TODAY%.tar \
C:\\application1 C:\\application2 "%USERPROFILE%\\Eigene Dateien" \
"%USERPROFILE%\\Lokale Einstellungen\\Anwendungsdaten\\Microsoft\\Outlook" \
>%LOGFILE%
rem echo Creating Backup Archive for remote computer(s)...
rem %BACKUP_ROOT%\tar.exe -cf %BACKUP_ROOT%\%ITEM%-%TODAY%.tar %BACKUP_DIR% \
>>%LOGFILE%
echo Creating CD-Image...
%BACKUP_ROOT%\mkisofs.exe -J -v -o %BACKUP_ROOT%\%ITEM%-%TODAY%.iso \
%BACKUP_ROOT%\%ITEM%-%TODAY%.tar >>%LOGFILE%
echo Deleting temporary files...
del /F /Q %BACKUP_ROOT%\%ITEM%-%TODAY%.tar >>%LOGFILE%
echo Burning CD
echo This make take some time, please be patient. A progress meter is being
echo displayed during the burning process and after the backup has
echo completed successfully, the CD will be ejected.
echo
%BACKUP_ROOT%\cdrecord dev=%CDDEVICE% gracetime=0 -tao -verbose -eject \
-data %BACKUP_ROOT%\%ITEM%-%TODAY%.iso
echo Deleting temporary files
del /F /Q %BACKUP_ROOT%\%ITEM%-%TODAY%.iso
echo
echo Backup completed successfully
echo
echo Please check if the CD is readable and that it contains a file
echo named %ITEM%-%TODAY%.tar
echo
pause
Downloads: