It should have been --exclude=/*/.* rather than --exclude=/home/*/.* The finished backup script can be found below, change WRITE='/media/backup' to wherever you want to back it up to (warning: if you back up to somewhere inside /home then it will recur one every time you backup, to avoid this add - /path/to/backup to the exclude-list). Thanks to unutbu and stroyan for correcting me.
/usr/local/bin/backup-home
Code:#!/bin/bash ##### CONSTANTS ##### NAME="${0##*/}" DESCRIPTION= VERSION=0.1 LOCATION="$(readlink -f $0)" LOCATION="${LOCATION%$NAME}" EXCLUDE="${LOCATION}exclude-list" WRITE='/media/backup' ##### MAIN CODE ##### guest=$(echo $1 | sed 's_[^#]*@\([^#]*\)_\1_') if [ "$(whoami)" != 'root' ]; then echo >&2 "Error: You must have root privileges to run this program." exit 1 fi while [ ! -d "$WRITE" ]; do echo >&2 "Please mount backup device at $WRITE and press [ENTER] to continue. Press [ESC] to postpone backup." if [ "$(wait-keypress )" == '' ]; then # Escape/Enter exit 0 fi done echo "The backup may take some time, please be patient..." if [ "$1" == '' ]; then rsync --delete -act /home/ $WRITE/$HOSTNAME:\ Home\ Backup/ --exclude-from="$EXCLUDE" else rsync --delete -act $1:/home/ $WRITE/$guest:\ Home\ Backup/ --exclude-from="$EXCLUDE" fi if [ "$?" == 0 ]; then echo "Backup completed successfully!" exit 0 else echo "Backup did not complete successfully." exit 1 fi
/usr/local/bin/exclude-list
Code:+ /*/.alaises + /*/.profile + /*/.*rc + /*/.devilspie/ - /*/.* - /lost+found
Bookmarks