Linux Backup Script



Here is a simple little script to perform a backup (tar.gz) a directory

#! /bin/bash
1) echo Backup Started `date` >> ~/backuplog
2) mkdir /home/myhome/backups/`date +%Y%m%d`
3) tar -czf /home/myhome/backups/`date +%Y%m%d`/filename.tar.gz ./folder-to-backup
4) echo Backup Completed `date` >> ~/backuplog

About this:

Don't enter the numbers in your script as these are just for documentation.

1) write a line to a log file (located in our users home directory by specifying the tilde ~ ) with the days date. This log file can be referenced to ensure that the backup is completed each day.

2) create the folder on our mounted usbdrive, in the backups folder with the days date in the format YYYYMMDD (example: 20060915).

3) creates the backup. On our file server we have created the folder-to-backup where we store everything. We have multiple directories within the folder-to-backup folder. Everything in that folder is compressed into an archive file using the tar command. The file is given the name folder-to-backup.tar.gz.

4) write a line to the backuplog telling us that the backup was completed and at what time.