Backing up data on a Windows machine using TAR and GZIP

Creating a Full Backup

You can create a simple batch file which calls both the tar and gzip programs in turn to create a compressed backup file, which contains all the data files in your specified directory.

Example1.bat

tar -cv –file=backup.tar d:/data*
gzip -9 < backup.tar > backup.tar.tgz
del backup.tar

Backing up More Than One Directory

You can set-up the batch file to backup multiple directory / folder tree structures. Example2.bat shown below demonstrates how this is achieved. You create the initial backup.tar file for your first directory using the -cv command. Then for every other directory structure, you use the -rv command to append the new directory / folder to the backup.tar file.

Example2.bat

tar -cv –file=backup.tar d:/data*
tar -rv –file=backup.tar d:/websites*
gzip -9 < backup.tar > backup.tar.tgz
del backup.tar

Creating an Incremental Backup

Creating an incremental backup is very easy, you just need to specify a date to the –newer command. Tar will then only include files which have changed since that date. The Example3.bat batch file shown below demonstrates creating an incremental backup for all files in the d:/data directory which have been modified since the 1st of September 2004.

Example3.bat

tar -cv –newer=2004-09-01 –file=incremental.tar d:/data*
gzip -9 < incremental.tar > incremental.tar.tgz
del incremental.tar

Download, References

http://downloads.cgi-interactive.net/tar-gzip.zip
http://www.gnu.org/software/tar/manual/index.html
http://www.gnu.org/software/gzip/manual/gzip.html

+ Recent posts