All pastes #770979 Raw Edit

Unnamed

public shellscript v1 · immutable
·published 2007-11-12 18:55 UTC
rendered paste body
#!/bin/shif [ `id -u` != "0" ]; then	echo "Not running as root!"	exit 2fi# Separate with a space. Exclude trailing slash!SOURCES="/"TARGET="/mnt/hda2"TARGETDEV="/mnt/hda2"# dirs and files to be excluded, one per line.# /proc/# *.bakEXCLUDE_FILE="/usr/local/share/backup-hda2-exclude.txt"LOGFILE="/var/log/backup.log"echo "$(date)" >> "$LOGFILE"{echo "Starting backup on $TARGET."TARGETMOUNTED=0echo "Verifying target..." if [ ! -d $TARGET/home ]; then	echo "Backup target is not mounted. Mounting..."	mount $TARGETDEV	if [ ! -d $TARGET/home ]; then		echo "Backup target does not exist or $TARGETDEV is not mountable!"		echo "Exiting..."		exit 2	else export TARGETMOUNTED=1	fielse export TARGETMOUNTED=2fiecho "Target verified."echo "Verifying sources..." for source in $SOURCES; do	echo "Checking $source..."	if [ ! -x $source ]; then	echo "Backup source does not exist!"	echo "Exiting..."	exit 2fidoneif [ -f $EXCLUDE_FILE ]; thenEXCLUDE="--exclude-from=$EXCLUDE_FILE"fiecho "Sources verified."for source in $SOURCES; do		if [ ! -d $TARGET/$source ]; then			echo "Mimicking sources directory hierarchy..."			mkdir -p $TARGET/$source		fi	echo "Running rsync..."	ionice -c3 nice -n19 rsync -av --exclude=$TARGET/ $EXCLUDE --delete $source/ $TARGET/$source/ "$@"doneecho "rsync finished."if [ $TARGETMOUNTED = 1 ]; then	sleep 2	umount $TARGETDEV	if [ -d $TARGET/home ]; then		echo "Couldn't unmount $TARGETDEV!"		echo "Exiting..."		exit 1	fi	echo "Backup target unmounted."fiif [ $TARGETMOUNTED = 2 ]; then	echo "Backup target was mounted and will remain mounted."fi} | tee -a $LOGFILEecho "" >> $LOGFILEexit 0