#!/bin/sh # 2004-04-25 by pille # # mount & sync disk to usb (sdb1) # # 2005-02-02 # + mount with -rw # + nice with -n (to be up to date) # + configured for kommunist (gentoo) # # 2005-03-20 # + BACKUP_DEST # # 2005-04-17 # + use rdiff-backup instead of rsync # # 2006-04-03 # + check for usb disk #### CONFIGURATION #### BACKUP_PATH="/" # backup these files BACKUP_PART="/dev/sdb1" # backup to this partition MOUNT_POINT="/mnt/usb" # ex. dir to mount usb-disk in BACKUP_DEST="${MOUNT_POINT}/gentoo" # where to store the backup RDIFF_BACKUP=`which rdiff-backup` RDIFF_BACKUP_OPTIONS="--terminal-verbosity 2 --verbosity 5 --exclude /proc --exclude /sys" #### FUNCTIONS #### # checks for attached backup-disk function check_backupdisk() { cat /proc/partitions | grep "8.*17.*78148161 sdb1" if [ $? == 0 ]; then return 1 else return 0 fi } # checks, wheather mountpoint is already mounted function check_mountpoint() { mount |grep "${MOUNT_POINT} " } #### MAIN #### # is our backup-disk attached? check_backupdisk if [ $? == 0 ]; then echo "ERROR: backup-disk not attached" exit -1 fi # is our mount-point already mounted? check_mountpoint if [ $? == 0 ]; then echo "ERROR: ${MOUNT_POINT} already mounted" exit -1 fi # mount the share echo "mounting ${BACKUP_PART} to ${MOUNT_POINT}..." mount -rw ${BACKUP_PART} ${MOUNT_POINT} if [ $? != 0 ]; then echo "ERROR: cannot mount ${BACKUP_PART} to ${MOUNT_POINT}" exit -2 fi # copy all the stuff nice -n -19 ${RDIFF_BACKUP} ${RDIFF_BACKUP_OPTIONS} ${BACKUP_PATH} ${BACKUP_DEST} echo RETURN CODE: $? df -h ${BACKUP_DEST} # unmount the share echo "unmounting ${BACKUP_PART} from ${MOUNT_POINT}..." umount ${MOUNT_POINT} if [ $? != 0 ]; then echo "ERROR: cannot unmount ${BACKUP_PART} from ${MOUNT_POINT}" exit -2 fi # at this point everting should be fine, so the next check should never occur # is our mount-point still mounted? check_mountpoint if [ $? == 0 ]; then echo "ERROR: ${MOUNT_POINT} still mounted (this should never happen)" exit -3 fi