diff options
| author | Marc Vertes <mvertes@free.fr> | 2020-07-29 16:31:28 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2020-07-29 16:31:28 +0200 |
| commit | 737ca59089a60edd0447db39775a97ec7fb96268 (patch) | |
| tree | d25804bab10d784ef6a66712fdc3e002ae5c9702 /bin | |
| parent | ad7f45231cb867990a03830ec09e0cd41959f539 (diff) | |
update
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/backup | 37 | ||||
| -rwxr-xr-x | bin/backup-clean | 9 | ||||
| -rwxr-xr-x | bin/byo | 5 | ||||
| -rwxr-xr-x | bin/diffdir | 21 |
4 files changed, 53 insertions, 19 deletions
@@ -3,21 +3,34 @@ [ "$USER" = root ] || exec sudo "$0" "$@" -while getopts :v opt; do +backup() { + date=$(date +%Y%m%d_%H%M%S) + last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1) + + case $last in + ([12]*) opt_link=--link-dest=../$last;; + (*) opt_link=;; + esac + + rsync -HSxa$optv --exclude-from=$ignore $opt_link / /boot "$dest/$date" +} + +dest=/.history +ignore=/etc/backup/ignore + +while getopts :d:i:nv opt; do case $opt in - (v) eval "opt$opt=$opt" ;; - (*) echo "Usage: $0 [-v] [[host:]dir]"; exit 1 ;; + (d) dest="$OPTARG" ;; + (i) ignore="$OPTARG" ;; + (n|v) optv="$opt$optv" ;; + (*) echo "Usage: $0 [-nv] [-d [host:]dir] [clean|diff]"; exit 1 ;; esac done shift $((OPTIND - 1)) -dest=${1:-/.history} -date=$(date +%Y%m%d_%H%M%S) -last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1) - -case $last in -([12]*) opt_link=--link-dest=../$last;; -(*) opt_link=;; +[ "$1" ] && cmd=$1 && shift || cmd="" +case $cmd in +(""|save) backup ;; +(clean) exec backup-clean ${optv+-$optv} "$@" "$dest";; +(diff) exec diffdir "$@";; esac - -rsync -HSxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot "$dest/$date" diff --git a/bin/backup-clean b/bin/backup-clean index 054ffbc..d12159d 100755 --- a/bin/backup-clean +++ b/bin/backup-clean @@ -26,7 +26,7 @@ date2ts() { t=$r; r=${t#??}; M=${t%$r} # Minute S=${t#??} # Second date -d "$Y-$m-$d $H:$M:$S" +%s - #date -jf "%Y-%m-%d %H:%M:%S" "$Y-$m-$d $H:$M:$S" +%s # BSD, MacOSX + #date -jf "%Y-%m-%d %H:%M:%S" "$Y-$m-$d $H:$M:$S" +%s # BSD, MacOS (not tested) } ts2date() { date -d "@$1" +'%Y%m%d_%H%M%S'; } @@ -53,17 +53,18 @@ retention_delay() { echo $r } -while getopts :nv opt; do +dest=/.history +while getopts :nd:v opt; do case $opt in + (d) dest=$OPTARG ;; (n) optn=1 ;; (v) optv=1 ;; - (*) echo "Usage: $0 [-nv] [dir]"; exit 1; + (*) echo "Usage: $0 [-nv] [-d dir]"; exit 1; esac done shift $((OPTIND - 1)) # Sorted list of backups, most recent first. -dest=${1:-/.history} lbu=$(ls -rv "$dest") for d in $lbu; do tsc=$(date2ts "$d") @@ -24,9 +24,10 @@ 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 -v "$dest" -backup-clean -v "$dest" +time backup -v -d "$dest" +backup -v -d "$dest" clean [ ! "$optd" ] || time duperemove -drh --hashfile="$dest/.hashfile" "$dest" +df -h / "$dest" [ ! "$optk" ] || noumount=1 noclose=1 [ ! "$optc" ] || noumount='' noclose='' [ "$noumount" ] || umount /mnt diff --git a/bin/diffdir b/bin/diffdir index d1a8ae2..cbe03b7 100755 --- a/bin/diffdir +++ b/bin/diffdir @@ -32,6 +32,20 @@ diffdir() { #key ~ /[cps]/ { print "changed " prefix file }' } +last() { + i=0 m=0 + case $1 in + ([0-9]|[1-9][0-9]) m=$((m + $1)) ;; + ("") ;; + (*) echo "$1"; return ;; + esac + for l in $vlist; do + [ $i -ge $m ] && break + i=$((i + 1)) + done + echo "$dest/$l" +} + while getopts :V opt; do case $opt in (V) echo "$Version"; exit ;; @@ -40,4 +54,9 @@ while getopts :V opt; do done shift $((OPTIND - 1)) -diffdir "$1" "$2" +dest=/.history +vlist=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tac) + +old=$(last "$1") new=$(last "${2:-/}") +echo "diffdir" "$old" "$new" +diffdir "$old" "$new" |
