summaryrefslogtreecommitdiff
path: root/bin/backup
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2021-12-06 15:02:31 +0100
committerMarc Vertes <mvertes@free.fr>2021-12-06 15:02:31 +0100
commite589eff80a403bfe7831c040fe55a6bcf5ba038b (patch)
tree8f13510610ce0a7020a141145c262cfec5b8367a /bin/backup
parent0b89577b1e7c46986bed003033d677f2d1ebf9cb (diff)
update
Diffstat (limited to 'bin/backup')
-rwxr-xr-xbin/backup55
1 files changed, 33 insertions, 22 deletions
diff --git a/bin/backup b/bin/backup
index 72c69c3..3964927 100755
--- a/bin/backup
+++ b/bin/backup
@@ -1,36 +1,47 @@
#!/bin/sh
-# Incremental backup using rsync(1).
-[ "$USER" = root ] || exec sudo "$0" "$@"
+usage() {
+ echo "Usage: $0 [-nv] [[[user@]host]:dir]
-backup() {
- date=$(date +%Y%m%d_%H%M%S)
- last=$(rsync --list-only "$dest/" 2>/dev/null | cut -b 47- | tail -1)
+Incremental backup using rsync(1). If run as root, a full system
+backup is performed. Otherwise, the user's home directory is backed.
- case $last in
- ([12]*) opt_link=--link-dest=../$last;;
- (*) opt_link=;;
- esac
+Options:
+-n dry-run
+-v verbose
- rsync -HSxa$optv --exclude-from=$ignore $opt_link / /boot "$dest/$date"
-}
+Files:
+- $HOME/.backupignore exclude files from user backup (non root)
+- /etc/backupignore exclude files from system backup (root)
-dest=/.history
-ignore=/etc/backup/ignore
+Environment:
+- BACKUP backup directory"
+}
-while getopts :d:i:nv opt; do
+while getopts :nv opt; do
case $opt in
- (d) dest="$OPTARG" ;;
- (i) ignore="$OPTARG" ;;
(n|v) optv="$opt$optv" ;;
- (*) echo "Usage: $0 [-nv] [-d [host:]dir] [clean|diff]"; exit 1 ;;
+ (*) usage; exit 1 ;;
esac
done
shift $((OPTIND - 1))
-[ "$1" ] && cmd=$1 && shift || cmd=""
-case $cmd in
-(""|save) backup ;;
-(clean) exec backup-clean ${optv+-$optv} "$dest";;
-(diff) exec diffdir "$@";;
+BACKUP=${1:-$BACKUP}
+[ "$BACKUP" ] || { usage; exit 1; }
+
+[ "$USER" = root ] &&
+ ignore=/etc/backupignore volumes='/ /boot' ||
+ 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)
+
+[ "$optv" ] && echo "# Backup $volumes to $BACKUP/$date"
+
+exec rsync -HSxa$optv $ignore $opt_link $volumes "$BACKUP/$date"