#!/bin/bash # This scripts backups all but temporary data on an other harddrive # If one harddrive fails, I still can boot from the other. # It uses rsync, which means only the changes since the last backup # are copied. # /backup is encrypted. See "Cryptoloop Howto" # First time: # losetup -e aes /dev/loop0 /dev/sda1 # mkfs.ext3 /dev/loop0 # losetup -d /dev/loop0 # Mount: # mount -t ext3 /dev/sda1 /backup -oencryption=aes # /etc/fstab # /dev/sda1 /backup auto rw,noauto,encryption=aes 0 0 set -u #modprobe cryptoloop #modprobe aes LOG_DIR=/var/log/backup LOG_FILE="$LOG_DIR/"`hostname`-`date --iso`.log BACKUPDIR="/media/backup" # $BACKUPDIR must be on an other harddrive, # an other partition makes no sense if mount $BACKUPDIR; then echo "$BACKUPDIR mounted" else echo "Can not mount $BACKUPDIR. Exit" exit 3 fi mkdir -p $LOG_DIR echo "Logfile: $LOG_FILE" echo "---Start Backup:" `date --iso` >> $LOG_FILE if [ ! -e $LOG_FILE ]; then echo "Logfile $LOG_FILE wurde nicht erstellt" exit 3 fi nice -19 incrisync backup rsync -avH --one-file-system \ --delete-excluded \ --delete \ --exclude '/tmp/*' \ --exclude '/var/tmp/*' \ --exclude '/var/run/*' \ --exclude '/var/log/ksymoops/*' \ --exclude '/var/cache/*' \ --exclude '/var/lock/*' \ --exclude '/var/log/*' \ --exclude '/var/backup/*' \ --exclude '/home/data/' \ --exclude '/home/guettli/tmp/' \ --exclude '/home/guettli/data/' \ --exclude '/home/guettli/Maildir/trash/*' \ --exclude '/home/guettli/.thunderbird/*/ImapMail/' \ --exclude '/home/guettli/Maildir/.spam/*' \ --exclude '/home/guettli/Maildir/.listen.*' \ --exclude '/home/guettli/.gvfs' \ --exclude '/home/guettli/.firefox/default/*/Cache' \ --exclude '/home/guettli/.thumbnails/*' \ --exclude '/home/guettli/.googleearth/*' \ --exclude '/home/guettli/.gimp*/*' \ --exclude '/home/guettli/.wine/*' \ --exclude '/home/guettli/.ies4linux/*' \ --exclude '/home/guettli/google-earth/*' \ --exclude '/home/guettli/.local/share/Trash/*' \ --exclude '/home/guettli/download/*' \ --exclude '/usr/lib/openoffice' \ --exclude '/usr/share/doc' \ --exclude '/usr/share/fonts/truetype' \ --exclude '/usr/share/ppd' \ --exclude '/usr/share/xemacs21' \ --exclude '/usr/share/texmf-tetex' \ --exclude '/usr/share/gnome/help' \ --exclude '/**/tmp' \ --exclude '*.pyc' \ --exclude '/var/backups/hetzner/years' \ --exclude '/var/backups/hetzner/months' \ / /home $BACKUPDIR/r51 >> "$LOG_FILE" 2>&1 ret=$? echo "---End Backup:" `date --iso` >> $LOG_FILE umount $BACKUPDIR echo "Tail of logfile:" tail $LOG_FILE if [ $ret -ne 0 ]; then echo "Exit Status != 0 !!!!!!!!!!!!!!!!!!!!!!!" fi exit $ret