Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 77 lines (67 sloc) 1.99 KB
#!/bin/sh
# checks if run as root
if ! [ "`whoami`" == "root" ]
then
echo "`basename $0`: must be root."
exit 1
fi
# checks for correct cmdline usage
if [ "$#" == "0" ]
then
echo "`basename $0`: too few arguments."
echo "syntax: \$ `basename $0` [-q|--quiet] <backup-filename> [custom-tar-options]"
echo "-q, --quiet: activates quiet mode (no confirmation)."
exit 1
fi
# checks for quiet mode (no confirmation)
if [ "$1" == "-q" ] || [ "$1" == "--quiet" ]
then
shift
AGREE="yes"
fi
# determines if filename was given with relative or absolute path
if [ "`echo $1 | grep -c '\/'`" -gt "0" ] && \
[ "`echo $1 | grep -c '^\/'`" -gt "0" ]
then
STAGE4_FILENAME="$1"
else
STAGE4_FILENAME="`pwd`/$1"
fi
# misc vars initialization block
shift;OPTIONS="$@"
EXCLUDES="\
--exclude=/proc/* \
--exclude=/sys/* \
--exclude=/tmp/* \
--exclude=/var/lock/* \
--exclude=/var/log/* \
--exclude=/var/run/* \
--exclude=.bash_history \
--exclude=lost+found \
--exclude=/usr/portage/* \
--exclude=$STAGE4_FILENAME"
TAR_OPTIONS="-cjpP --ignore-failed-read -f"
# if not in quiet mode, this message will be displayed
if [ "$AGREE" != "yes" ]
then
echo "Are you sure that you want to make a complete system-backup now?"
echo ""
echo "NOTE: external filesystems which should not be saved must be"
echo "unmounted before backing up or their mountpoints excluded per cmdline."
echo "example: \$ `basename $0` /my-backup.tar.bz2 --exclude=/mnt/samba/* ..."
echo ""
echo "WARNING: since all data is saved by default the user should exclude all"
echo "security- or privacy-related files and directories manually per cmdline."
echo "example: \$ `basename $0` /my-backup.tar.bz2 --exclude=/etc/ssh/ssh_host*"
echo ""
echo -e "COMMAND LINE PREVIEW:\n\$ tar $TAR_OPTIONS $STAGE4_FILENAME / $EXCLUDES $OPTIONS"
echo ""
echo -n "Type \"yes\" to continue or anything else to quit: "
read AGREE
fi
# start stage4 creation
if [ "$AGREE" == "yes" ]
then
tar $TAR_OPTIONS $STAGE4_FILENAME / $EXCLUDES $OPTIONS
fi
exit 0