Hi guys. Here's a simple backup script to help archive the contents of your home directory. Currently, it supports six different archiving methods:
tar/bzip, tar/xz, tar/gzip, tar/t7z, rar, zip
If you have any ideas to make it better, I'm all ears...
tar/bzip, tar/xz, tar/gzip, tar/t7z, rar, zip
If you have any ideas to make it better, I'm all ears...
Code:
#!/bin/sh
# This script provides a rolling backup scheme for your home directory & prunes
# archives greater than 7 days old, example output: ~/backup/mike-20130101.zip
#
# |||(__) ^ FreeBSD ~/backup script
# | ( )( [c]2013 Topcat Software LLC.
# |-- >_) http://topcat.hypermart.net
# | _||_ All rights reserved.
# ----------------------------------------------------------------------------
# path to backup directory & name of archive
DIR=$HOME/backup
OBJ=$DIR/$USER-`date "+%Y%m%d"`
# ----------------------------------------------------------------------------
# create ~/backup directory if it doesn't exist
[ -d $DIR ] || mkdir $DIR
# ----------------------------------------------------------------------------
# prune backups, choose one extension of .tbz .txz .tgz .t7z .rar .zip
find $DIR/ -type f -iname $USER-'[0-9]*'.zip -maxdepth 1 -mtime +7 -delete
# ----------------------------------------------------------------------------
# choose archive type: tar/bzip tar/xz tar/gzip tar/7zip rar zip
#tar --exclude=$DIR -jcvf $OBJ.tbz $HOME
#tar --exclude=$DIR --options xz:9 --xz -cvf $OBJ.txz $HOME
#tar --exclude=$DIR --options gzip:9 -zcvf $OBJ.tgz $HOME
#tar --exclude=$DIR -cvf - $HOME | 7za a -mx=9 -si $OBJ.t7z
#rar a -m5 -s -r -ol -x$DIR/ $OBJ.rar $HOME
zip -9r -x$DIR/\* $OBJ.zip $HOME
# ----------------------------------------------------------------------------
# choose notification method (syslog or mail) if backup fails
#ERR=$?; [ $ERR -eq 0 ] || logger -t backup error: $ERR
ERR=$? ; [ $ERR -eq 0 ] || echo backup error: $ERR | mail -s backup $USER
# eof