summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/backup37
-rwxr-xr-xbin/backup-clean9
-rwxr-xr-xbin/byo5
-rwxr-xr-xbin/diffdir21
4 files changed, 53 insertions, 19 deletions
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"
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")
diff --git a/bin/byo b/bin/byo
index 71b7578..ecaba23 100755
--- a/bin/byo
+++ b/bin/byo
@@ -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"