diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/backup | 17 | ||||
| -rwxr-xr-x | bin/byo | 34 |
2 files changed, 41 insertions, 10 deletions
@@ -1,17 +1,12 @@ #!/bin/sh +# Incremental backup using rsync(1). [ "$USER" = root ] || exec sudo "$0" "$@" -# incremental backup using rsync(1) - -die() { echo "$0: fatal: $@" >&2; exit 1; } - -#[ "$(id -u)" = 0 ] || die must run as root - -while getopts :v opt; do +while getopts :Fv opt; do case $opt in - (v) optv=v ;; - (*) echo "Usage: $0 [-v] [[host:]dir]"; exit 1 ;; + (F|v) eval "opt$opt=$opt" ;; + (*) echo "Usage: $0 [-Fv] [[host:]dir]"; exit 1 ;; esac done shift $((OPTIND - 1)) @@ -25,4 +20,6 @@ case $last in (*) opt_link=;; esac -rsync -DSHxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot $dest/$date +[ "$optF" ] && fsfreeze -f / && trap 'fsfreeze -u /' EXIT + +rsync -HSxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot $dest/$date @@ -0,0 +1,34 @@ +#!/bin/sh -e +# Backup to yoda +[ "$USER" = root ] || exec sudo "$0" "$@" + +usage='Usage: byo [-cdk] +Backup local disk to yoda external disk. + +Options: + -c close and umount yoda + -d dedupe yoda + -k do not umount and close yoda +' + +while getopts :cdk opt; do + case $opt in + (c|d|k) eval "opt$opt=$opt" ;; + (*) printf %s "$usage"; exit 1 ;; + esac +done +shift $((OPTIND - 1)) + +yoda_uuid='8c463221-6bb7-414e-9060-c9570bb3a6bb' + +dest=/mnt/backup/$(hostname) +[ -b /dev/mapper/yoda ] && noclose=1 || cryptsetup open "$(blkid --uuid "$yoda_uuid")" yoda +findmnt /dev/mapper/yoda /mnt >/dev/null && noumount=1 || mount /dev/mapper/yoda /mnt +time backup -Fv "$dest" +backup-clean -v "$dest" +[ ! "$optd" ] || time duperemove -drh --hashfile="$dest/.hashfile" "$dest" +[ ! "$optk" ] || noumount=1 noclose=1 +[ ! "$optc" ] || noumount='' noclose='' +[ "$noumount" ] || umount /mnt +[ "$noclose" ] || cryptsetup close yoda +echo "bye" |
