#!/bin/sh ROOT_UID=0 # Only users with $UID 0 have root privileges. E_NOTROOT=67 # Non-root exit error. # Run as root, of course. if [ "$UID" -ne "$ROOT_UID" ]; then echo "Must be root to run this script." exit $E_NOTROOT fi mount /mnt/backup # full and incremental backup script # created 07 February 2000 # Based on a script by Daniel O'Callaghan # and modified by Gerhard Mourani #Change the 5 variables below to fit your computer/backup COMPUTER=`hostname -s` # name of this computer DIRECTORIES="/home /etc /var" # directoris to backup EXCLUDES="--exclude=var/run/*" # directoris to excludes BACKUPDIR=/mnt/backup # where to store the backups TIMEDIR=/mnt/backup/last-full # where to store time of full backup TAR=/bin/tar # name and locaction of tar OPTIONS="--selinux --sparse" # tar options # Does lzop package exists? rpm_lzop=`rpm -q lzop` if [ $? -eq 0 ]; then # Test exit status of "rpm" command. OPTIONS="--selinux --sparse --use-compress-program=lzop" else echo Need to install the lzop package when time permits to compress the backups fi #You should not have to change anything below here PATH=/usr/local/bin:/usr/bin:/bin DOW=`date +%a` # Day of the week e.g. Mon DOM=`date +%d` # Date of the Month e.g. 27 DM=`date +%d%b` # Date and Month e.g. 27Sep # On the 1st of the month a permanet full backup is made # Every Sunday a full backup is made - overwriting last Sundays backup # The rest of the time an incremental backup is made. Each incremental # backup overwrites last weeks incremental backup of the same name. # # if NEWER = "", then tar backs up all files in the directories # otherwise it backs up files newer than the NEWER date. NEWER # gets it date from the file written every Sunday. # Monthly full backup if [ $DOM = "01" ]; then NEWER="" $TAR $OPTIONS $NEWER -cpf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES $EXCLUDES fi # Weekly full backup if [ $DOW = "Sun" ]; then NEWER="" NOW=`date +%d-%b` # Update full backup date echo $NOW > $TIMEDIR/$COMPUTER-full-date $TAR $OPTIONS $NEWER -cpf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES $EXCLUDES # Make incremental backup - overwrite last weeks else # Get date of last full backup NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`" $TAR $OPTIONS $NEWER -cpf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES $EXCLUDES fi umount /mnt/backup