summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bashrc1
-rwxr-xr-xbin/backup17
-rwxr-xr-xbin/byo34
3 files changed, 42 insertions, 10 deletions
diff --git a/.bashrc b/.bashrc
index 771c00e..14c87b7 100644
--- a/.bashrc
+++ b/.bashrc
@@ -38,6 +38,7 @@ alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date
export TERMINAL=xt
alias cl='cf xft:Mono:size=12'
+alias cp='cp --reflink'
alias ls='ls --color=auto -v'
alias ll='ls -AlFhv'
alias vi='vim'
diff --git a/bin/backup b/bin/backup
index 3f1d586..059f2dc 100755
--- a/bin/backup
+++ b/bin/backup
@@ -1,17 +1,12 @@
#!/bin/sh
+# Incremental backup using rsync(1).
[ "$USER" = root ] || exec sudo "$0" "$@"
-# incremental backup using rsync(1)
-
-die() { echo "$0: fatal: $@" >&2; exit 1; }
-
-#[ "$(id -u)" = 0 ] || die must run as root
-
-while getopts :v opt; do
+while getopts :Fv opt; do
case $opt in
- (v) optv=v ;;
- (*) echo "Usage: $0 [-v] [[host:]dir]"; exit 1 ;;
+ (F|v) eval "opt$opt=$opt" ;;
+ (*) echo "Usage: $0 [-Fv] [[host:]dir]"; exit 1 ;;
esac
done
shift $((OPTIND - 1))
@@ -25,4 +20,6 @@ case $last in
(*) opt_link=;;
esac
-rsync -DSHxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot $dest/$date
+[ "$optF" ] && fsfreeze -f / && trap 'fsfreeze -u /' EXIT
+
+rsync -HSxa$optv --exclude-from=/etc/backup/ignore $opt_link / /boot $dest/$date
diff --git a/bin/byo b/bin/byo
new file mode 100755
index 0000000..173c2a7
--- /dev/null
+++ b/bin/byo
@@ -0,0 +1,34 @@
+#!/bin/sh -e
+# Backup to yoda
+[ "$USER" = root ] || exec sudo "$0" "$@"
+
+usage='Usage: byo [-cdk]
+Backup local disk to yoda external disk.
+
+Options:
+ -c close and umount yoda
+ -d dedupe yoda
+ -k do not umount and close yoda
+'
+
+while getopts :cdk opt; do
+ case $opt in
+ (c|d|k) eval "opt$opt=$opt" ;;
+ (*) printf %s "$usage"; exit 1 ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+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 -Fv "$dest"
+backup-clean -v "$dest"
+[ ! "$optd" ] || time duperemove -drh --hashfile="$dest/.hashfile" "$dest"
+[ ! "$optk" ] || noumount=1 noclose=1
+[ ! "$optc" ] || noumount='' noclose=''
+[ "$noumount" ] || umount /mnt
+[ "$noclose" ] || cryptsetup close yoda
+echo "bye"