chiark / gitweb /
add backup and backup.withlock scripts
authorwry@lapis <wry@lapis>
Wed, 23 Jun 2010 14:29:48 +0000 (15:29 +0100)
committerwry@lapis <wry@lapis>
Wed, 23 Jun 2010 14:29:48 +0000 (15:29 +0100)
chiark-cryptdisk/Makefile
chiark-cryptdisk/chiark-cryptdisk-backup [new file with mode: 0755]
chiark-cryptdisk/chiark-cryptdisk-backup.withlock [new file with mode: 0755]

index 4714857..9ad1924 100644 (file)
@@ -39,7 +39,8 @@ txtdocdir=$(prefix)/share/doc/chiark-cryptdisk
 exampledir=$(txtdocdir)/examples
 
 ETCFILES=config
-LIBFILES=examine functions search-for-sata unmount
+LIBFILES=examine functions search-for-sata unmount \
+                chiark-cryptdisk-backup chiark-cryptdisk-backup.withlock
 SCRIPTS=initialise-disk make-key
 
 MANPAGES5=     
diff --git a/chiark-cryptdisk/chiark-cryptdisk-backup b/chiark-cryptdisk/chiark-cryptdisk-backup
new file mode 100755 (executable)
index 0000000..0b06bd0
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash -e
+
+LOCKFILE=/var/lock/chiark-cryptdisk-backup
+with-lock-ex -w $LOCKFILE /usr/lib/chiark-cryptdisk/cryptdisk-backup.withlock "$@"
+
diff --git a/chiark-cryptdisk/chiark-cryptdisk-backup.withlock b/chiark-cryptdisk/chiark-cryptdisk-backup.withlock
new file mode 100755 (executable)
index 0000000..b8be18e
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash -e
+# Sample backup script for use with chiark-cryptdisk.
+# Copyright 2008-2010 W. Ross Younger.
+# 
+# The chiark utilities are all free software; you can redistribute them
+# and/or modify them under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 3 of the
+# License, or (at your option) any later version.
+
+
+# Usage: (no options)
+
+. /etc/chiark-cryptdisk/config
+
+#DRYRUN=--dry-run
+
+#############################################
+mountcrypt() {
+       $lib/examine --rw > /dev/null || (echo Could not mountcrypt ':(' && false)
+}
+
+umountcrypt() {
+       $lib/unmount
+}
+
+closeall() {
+       umountcrypt
+}
+
+#############################################
+
+trap closeall ERR
+
+mountcrypt
+
+# TODO: Ensure there's enough space on the disk by removing older backups until there is... Or, at least, some reporting process should do so.
+
+DISKID=`cat $mnt/disk-id`
+
+stamp=`date`
+stampfn=`date +%Y%m%d%H%M`
+STAMP_DISK=$mnt/stamp
+
+SRC=/
+DST=${mnt}/snap.${stampfn}
+
+CATALOGUE=/etc/backup-catalogue/$DISKID
+STAMP_CAT=$CATALOGUE/${stampfn}
+
+prev=`cat $STAMP_DISK` 2>/dev/null || prev="nonexistent"
+PREVBACKUP=${mnt}/snap.${prev}
+
+echo "This is backup snap shot ${stampfn}; this disk's prev is ${prev}"
+
+#set -x
+rsync -ax --delete $DRYRUN --link-dest=${PREVBACKUP} $SRC/ $DST
+#set +x
+
+echo $stampfn > $STAMP_DISK
+mkdir -p $CATALOGUE
+echo $stampfn > $STAMP_CAT
+
+closeall > /dev/null
+
+echo "- completed ok"