All pastes #770764 Raw Edit

Stuff

public shellscript v1 · immutable
·published 2007-11-12 15:57 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"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 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 --progress --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/ "$@"doneif [ $TARGETMOUNTED = 1 ]; then	sleep 2	umount $TARGETDEV	if [ -d $TARGET/home ]; then		echo "Backup target still mounted!"		echo "Exiting..."		exit 1	fi	echo "Backup target unmounted."fiif [ $TARGETMOUNTED = 2 ]; then	echo "Backup target was mounted and will remain mounted."fiexit 0