It is my opinion that the user home directory is one of the most important directories of any *nix system. The rest of the system can be reinstalled from the source media at any time, but the user home directory can only be restored from an existing backup. The problem with backups is that many people don't perform them as often as they should.
In light of this, I have written a simple bash script that makes a backup archive of $HOME:
Remember to replace $USER in the above script with your username. The resulting file will be named, for example, backups-20091231.tar.bz2 and I highly recommend running this script in a cronjob for automated backups. Please see my crontab tutorial for more information about cronjobs.Code:#!/bin/bash # Filename: mybackups.sh # Version: 0.8 # Author: Ian MacGregor (aka ardchoille) # License: GPL # Description: This script makes backup archives of $HOME # Edit this to reflect your preferred destination directory backupdir="/mnt/sdb1/archives/personal" # Edit this to reflect your preferred temporary file name backuptemp="temp.tar.bz2" # Edit this to reflect your preferred final file name # See man strftime for options other than %Y%m%d backupfile="backups-$(date +%Y%m%d).tar.bz2" # Remove any existing backup files rm -f $backupdir/backups* # Change directory cd /home # Tar up all files in $HOME tar -cjf $backupdir/$backuptemp --exclude='.gvfs' $USER # Change the path of the tarball mv $backupdir/$backuptemp $backupdir/$backupfile # Done exit
I'm posting this in the hopes that it will be of use to someone.
UPDATE: January 1, 2010 - Updated the script to remain silent during removal of old backup file.
UPDATE: January 3, 2010 - Updated the script to fix backup file removal bug.



Adv Reply





Bookmarks