summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2022-10-01 12:41:24 +0200
committerMarc Vertes <mvertes@free.fr>2022-10-01 12:41:24 +0200
commit5b201b3fcd94c8bad917e2b45dbb1105cb060cdb (patch)
treeda07dec039695cc4abf0e01607bbe79357b2549c /bin
parent9f8cb54bd99b89a2f07bba4f4d1f761fd853b195 (diff)
update
Diffstat (limited to 'bin')
-rwxr-xr-xbin/backup26
1 files changed, 17 insertions, 9 deletions
diff --git a/bin/backup b/bin/backup
index d682849..9e73703 100755
--- a/bin/backup
+++ b/bin/backup
@@ -1,5 +1,7 @@
#!/bin/sh
+# A backup a day keeps the doctor away.
+
usage() {
echo "Usage: $0 [-nv] [[[user@]host]:dir]
@@ -34,13 +36,19 @@ BACKUP=${1:-$BACKUP}
ignore="$HOME/.backupignore" volumes="$HOME"
[ -f "$ignore" ] && ignore="--exclude-from=$ignore" || ignore=
-last=$(rsync --list-only "$BACKUP/" 2>/dev/null | awk '{r=$NF} END {print r}')
-case $last in
-([12]*) opt_link=--link-dest=../$last;;
-(*) opt_link=;;
-esac
-
-date=$(date +%Y-%m-%d-%H%M%S)
+now=$(date +%F)
+opt_link=''
+past=$(rsync --list-only "$BACKUP/" 2>/dev/null | awk '{print $NF}' | sort -r)
+for f in $past
+do
+ case $f in
+ ([0-9][0-9][0-9][0-9]-*) ;;
+ (*) continue ;;
+ esac
+ [ "$f" = "$now" ] && continue
+ opt_link="--link-dest=../$f"
+ break
+done
-echo "# Backup $volumes to $BACKUP/$date"
-exec rsync -HSxa$optv $ignore $opt_link $volumes "$BACKUP/$date"
+echo "# Backup $volumes to $BACKUP/$now"
+exec rsync -HSXxa$optv $ignore $opt_link $volumes "$BACKUP/$now"