Skip to content

Instantly share code, notes, and snippets.

@ksophocleous
Created February 18, 2014 09:50
Show Gist options
  • Save ksophocleous/9067766 to your computer and use it in GitHub Desktop.
Save ksophocleous/9067766 to your computer and use it in GitHub Desktop.
so much (ba)sh awesomeness in this script
#!/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
"/mnt") ;;
"/mnt/"*) ;;
"/media") ;;
"/media/"*) ;;
*) echo "Destination not allowed." >&2
exit 1
;;
esac
START=$(date +%s)
rsync -aAXv /* $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