#!/bin/bash # example of simple incremental / full backup script # 1-6000 second random delay (prevents all student virtual hosts from taking backups simultaneously) # uncomment these two lines before implementing to the server with crontab scheduler: #mydelay=$(shuf -i 1-6000 -n 1) #sleep $mydelay # testing and creating backup directories if [ ! -e /mnt/backup/ ]; then mkdir /mnt/backup; fi if [ ! -e /mnt/backup/increment ]; then mkdir /mnt/backup/increment; fi if [ ! -e /mnt/backup/full ]; then mkdir /mnt/backup/full; fi # filesize set to unlimited and default file permissions ulimit -f unlimited umask 066 # setting locations of individual backups DATA1="/etc" DATA2="/usr/local" DATA3="/home" LIST=$(mktemp) # temporary filename for filename list(s) set $(date) # date output will go to $1, $2 etc # Full backups if Sunday if test "$1" = "Sun" ; then tar cfz "/mnt/backup/full/full_backup_etc.tar.gz" $DATA1 >& /dev/null tar cfz "/mnt/backup/full/full_backup_usr_local.tar.gz" $DATA2 >& /dev/null tar cfz "/mnt/backup/full/full_backup_home.tar.gz" $DATA3 >& /dev/null rm -f /mnt/backup/increment/increment* else # Incremental backups if not Sunday: Backup new or within 1 day modified files # Find locates the files and tar creates the backup archive find $DATA1 -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST tar cfzT "/mnt/backup/increment/increment_etc_$6-$2-$3.tar.gz" "$LIST" >& /dev/null find $DATA2 -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST tar cfzT "/mnt/backup/increment/increment_usr_local_$6-$2-$3.tar.gz" "$LIST" >& /dev/null find $DATA3 -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST tar cfzT "/mnt/backup/increment/increment_home_$6-$2-$3.tar.gz" "$LIST" >& /dev/null rm -f "$LIST" # deleting the temporary file before exit fi