I'll be the first to post a program here
xd , this is a bash shell script to back up a system to pretty much any kind of location and/or device, and capable of full and incremental backups.
#!/bin/sh
# Backup - create either a full or incremental backup of a set of
# defined directories on the system. By default, the output
# file is saved in /tmp with a timestamped filename, compressed.
# Otherwise, specify an output device (another disk, a removable).
# Help and usage sections, this is a bit lacking...
usageQuit()
{
cat << "EOF" >&2
Usage: $0 [-o output] [-i|-f] [-n]
-o lets you specify an alternative backup file/device
-i is an incremental or -f is a full backup, and -n prevents
updating the timestamp if an incremental backup is done.
EOF
exit 1
}
# program settings
compress="bzip2" # change for your favorite compression app
inclist="/tmp/backup.inclist.$(date +%d%m%y)"
output="/tmp/backup.$(date +%d%m%y).bz2" # default output is /tmp, but can be changed to other devices including, external HDD, CD/DVD writer, FTP server, etc...
outputdevice="/tmp" #the device to backup to (same as above, just without the "/backup.$(date+%d%m%y).bz2
tsfile="$HOME/.backup.timestamp" #Backup timestamp, needed to do a incremental backup
btype="incremental" # default to an incremental backup
noinc=0 # and an update of the timestamp
trap "/bin/rm -f $inclist" EXIT
while getopts "o:ifn" opt; do
case "$arg" in
o ) output="$OPTARG"; ;;
i ) btype="incremental"; ;;
f ) btype="full"; ;;
n ) noinc=1; ;;
? ) usageQuit ;;
esac
done
shift $(( $OPTIND - 1 ))
# Test to see if the output device is mounted
if [ ! -d $outputdevice ] ; then
clear
echo "Error: The device is not mounted or is not present, can not backup"
exit 1
fi
# If the output device is mounted then start backup
echo "Doing $btype backup, saving output to $output"
timestamp="$(date +%m%d%I%M)"
# Run check for .backup.timestamp file, if not found offer the user to create one for them (running a full backup)
if [ "$btype" = "incremental" ] ; then
if [ ! -f $tsfile ] ; then
echo "Error: No .backup.timestamp file found, can not preform Incremental backup" >&2
echo "Do you want me to make one for you? (y/n) Note: This will run a full backup"
read ans
if [ $ans = "y" ] ; then
find $HOME -depth -type f -user ${USER:-LOGNAME} |
pax -w -x tar | $compress > $output
echo "Your $btype backup is done and is in $output"
touch -t $timestamp $tsfile
echo "Timestamp file has been made"
exit 1
else
exit 1
fi
fi
# Incremental backup
find $HOME -depth -type f -newer $tsfile -user ${USER:-LOGNAME} |
pax -w -x tar | $compress > $output
failure="$?"
echo "Your $btype backup is done and is in $output"
else
# Full backup
find $HOME -depth -type f -user ${USER:-LOGNAME} |
pax -w -x tar | $compress > $output
failure="$?"
echo "Your $btype backup is done and is in $output"
fi
# Test to see if the user wants to update the timestamp and act accordingly
if [ "$noinc" = "0" ] ; then
touch -t $timestamp $tsfile
sleep 5
clear
echo "The timestamp has been updated to:"
date
fi
exit 0
Yea I don't make my code very neat, but it does work and if any one wants to use it, I think that it is well documented enough for anyone to set it up the way they want.