Skip to content

Instantly share code, notes, and snippets.

@cldotdev
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save cldotdev/8970365 to your computer and use it in GitHub Desktop.

Select an option

Save cldotdev/8970365 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -lt 1 ]; then
echo "No destination defined. Usage: $0 destination" >&2
exit 1
elif [ $# -gt 1 ]; then
echo "Too many arguments. Usage: $0 destination" >&2
exit 1
elif [ ! -d "$1" ]; then
echo "Invalid path: $1" >&2
exit 1
elif [ ! -w "$1" ]; then
echo "Directory not writable: $1" >&2
exit 1
fi
case "$1" in
"/run/"*) ;;
"/mnt") ;;
"/mnt/"*) ;;
"/media") ;;
"/media/"*) ;;
*) echo "Destination not allowed." >&2
exit 1
;;
esac
START=$(date +%s)
rsync -aAXv --delete /* $1 --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/var/lib/pacman/sync/*}
FINISH=$(date +%s)
echo "total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds" | tee $1/"Backup from $(date '+%A, %d %B %Y, %T')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment