commit a7c80bd17d4f7f411794d8657eed16f67aa49a02
parent 0e1aa78b46ca8cd35d6740a5b00bfd059d966624
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 4 Jul 2019 09:23:12 +0200
Add unified backup script
Diffstat:
3 files changed, 65 insertions(+), 23 deletions(-)
diff --git a/.local/bin/backup b/.local/bin/backup
@@ -0,0 +1,65 @@
+#!/bin/sh
+
+show_help() {
+ echo "usage: ${0##*/} [OPTIONS] TARGET"
+ echo "is a wrapper for rsync backing up /home and /etc to TARGET"
+ echo
+ echo "OPTIONS are one or more of the following:"
+ echo " -h, --help show this message"
+ echo " -v, --version show version and license information"
+ echo " -- do not consider any following args as options"
+}
+
+show_version() {
+ echo "${0##*/} version $version"
+ echo "Licensed under the GNU Public License, v3+"
+ echo "written by Anders Damsgaard, anders@adamsgaard.dk"
+ echo "https://gitlab.com/admesg/dotfiles"
+}
+
+die() {
+ printf '%s\n' "$1" >&2
+ exit 1
+}
+
+
+backup() {
+ rsync -ravzhe ssh --delete /etc/ "$1"/etc/
+ rsync -ravzhe ssh --delete --progress \
+ --exclude=tmp \
+ --exclude=.cache \
+ --exclude=videos/tmp \
+ --exclude=tags \
+ --exclude=.julia \
+ --exclude='.config/surf/cache' \
+ ~/ "$1"/home/ad/
+}
+
+while :; do
+ case "$1" in
+ -h|-\?|--help)
+ show_help
+ exit 0
+ ;;
+ -v|--version)
+ show_version
+ exit 0
+ ;;
+ --) # end all options
+ shift
+ break
+ ;;
+ -?*)
+ die 'Error: Unknown option specified'
+ ;;
+ *) # No more options
+ break
+ esac
+ shift
+done
+
+if [ $# -lt 1 ]; then
+ die 'error: no TARGET specified, see --help'
+fi
+
+backup "$1"
diff --git a/.local/bin/backup-adamsgaard b/.local/bin/backup-adamsgaard
@@ -1,11 +0,0 @@
-#!/bin/sh
-dest=ad@adamsgaard.dk:/Volumes/ext2/backup
-rsync -ravzhe ssh --delete /etc/ "$dest"/etc/
-rsync -ravzhe ssh --delete --progress \
- --exclude=tmp \
- --exclude=.cache \
- --exclude=videos/tmp \
- --exclude=tags \
- --exclude=.julia \
- --exclude='.config/surf/cache' \
- ~/ "$dest"/home/ad/
diff --git a/.local/bin/backup-usb b/.local/bin/backup-usb
@@ -1,12 +0,0 @@
-#!/bin/sh
-dest=/mnt/backup
-rsync -ravzhe ssh --delete /etc/ "$dest"/etc/
-mount "$dest"
-rsync -ravzhe ssh --delete --progress \
- --exclude=tmp \
- --exclude=.cache \
- --exclude=videos/tmp \
- --exclude=tags \
- --exclude=.julia \
- --exclude='.config/surf/cache' \
- ~/ "$dest"/home/ad/