From ea18410af09ef8ef4f044079a72c82b2d41151a4 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 29 Jul 2020 16:31:28 +0200 Subject: update --- bin/backup | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'bin/backup') diff --git a/bin/backup b/bin/backup index 4ef83be..d56ee7f 100755 --- a/bin/backup +++ b/bin/backup @@ -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" -- cgit v1.2.3