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.tgz
del backup.tar
Line 1 of the Example1.bat shown above, demonstrates creating a tar file called backup.tar which will contain all the files and sub directories under d:/data you will need to substitute d:/data with your own drive and directory name. The second line shows how to compress the backup.tar using gzip. The -9 command instructs gzip to use the maximum compression and output the compressed file to a new file named backup.tar.tgz. The last line of the batch file deletes the backup.tar file so that you are only left with the compressed version of the backup backup.tar.tgz.
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.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 December 2006.
Example3.bat
tar -cv --newer=2006-12-01 --file=incremental.tar d:/data*
gzip -9 <> incremental.tar.tgz
del incremental.tar