Created
January 7, 2017 15:37
-
-
Save cyphunk/2b4dfc0db6f91a6b67a6b63b09058c21 to your computer and use it in GitHub Desktop.
backup script wrapper around duplicity backup app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make certain only root and edit this script. | |
l=($(ls -l `readlink -f $0`)) | |
[ ${l[0]:2:1} != "-" ] && [ "${l[2]}" != "root" ] || | |
[ ${l[0]:5:1} != "-" ] && [ "${l[3]}" != "root" ] || | |
[ ${l[0]:8:1} != "-" ] && { | |
echo -e "Script uses or is called from sudo often.\nOnly root should be able to modify.\n${l[@]}"; | |
exit 1;} | |
usage_self () | |
{ | |
echo -en "usage: `basename \"$0\"` "; | |
grep '^ *[^ \(\*]*)' $0 | xargs | sed 's/)//g' | sed 's/ +/ /g' | sed 's/ /\|/g' | sed 's/--//g'; | |
echo ""; | |
grep -A 30 '^ *[^ \(\*]*)' $0 | egrep -B 1 '^ #' | sed 's/#//' | sed 's/--//g'; | |
echo "" | |
} | |
test $# -lt 2 && usage_self && exit 1 | |
case "$1" in | |
show) | |
# show <src> [depth] [filter] | |
# shows status and list of and files from source backup | |
$0 status $2 | |
$0 list $2 $3 $4 | |
;; | |
status) | |
CMD="duplicity collection-status file://$2" | |
;; | |
list) | |
# list <src> [depth] list files in source backup | |
echo "$3" | egrep -q '^[0-9]+$' && DEPTH=$3 && FILTER=$4 | |
echo "$4" | egrep -q '^[0-9]+$' && DEPTH=$4 && FILTER=$3 | |
CMD="duplicity list-current-files file://$2 | awk '{print \$6}' " | |
test -n "$FILTER" && CMD="$CMD | egrep \"$FILTER\"" | |
test -n "$DEPTH" && CMD="$CMD | cut -d'/' -f1-$DEPTH | uniq -c " | |
;; | |
restore) | |
# restore <src> <dst> [relpath] | |
# restore from src to dst with optional relpath | |
# relpath is the same as found from list cmd | |
test -n "$4" && RELPATH="$4" | |
CMD="duplicity restore " | |
test -n "$RELPATH" && CMD="$CMD --file-to-restore \"$4\"" | |
CMD="$CMD file://$2 $3" | |
test -n "$RELPATH" && CMD="$CMD/$RELPATH" | |
;; | |
backup) | |
# backup <src> <dst> | |
CMD="sudo duplicity $2 file://$3" | |
;; | |
*) | |
$0 backup $2 $3 | |
;; | |
esac | |
echo -e "$CMD" | |
read -p "execute [y]/n? " YN | |
test "$YN" = "n" || eval "$CMD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment