]> arthur.barton.de Git - ax-linux.git/commitdiff
Add btrfs-mksnapshot-rootfs script
authorAlexander Barton <alex@barton.de>
Fri, 25 Apr 2014 08:54:43 +0000 (10:54 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 25 Apr 2014 09:02:52 +0000 (11:02 +0200)
This script is a wrapper for btrfs-mksnapshot script, which creates a
daily snapshot of the root filesystem (/) if it is of type "btrfs" and
when the btrfs-mksnapshot tool is available.

If the root filesystem is not of type "btrfs" or when btrfs-mksnapshot is
not available, it exits WITHOUT an error code, so it is safe to use this
wrapper even on systems which don't use btrfs at all (this is useful for
/etc/apt/apt.conf.d/06btrfs-mksnapshot, for example).

btrfs/mksnapshot/06btrfs-mksnapshot
btrfs/mksnapshot/Makefile
btrfs/mksnapshot/btrfs-mksnapshot-rootfs [new file with mode: 0755]

index 182570efd1f94bb88ccdd115d0e4d27bd5a8dd45..3b2e0418e378c366fd4284656c4ba61920e56524 100644 (file)
@@ -1 +1 @@
-DPkg::Pre-Invoke { "if [ -x /usr/local/sbin/btrfs-mksnapshot ]; then /usr/local/sbin/btrfs-mksnapshot -1 /; fi"; };
+DPkg::Pre-Invoke { "if [ -x /usr/local/sbin/btrfs-mksnapshot-rootfs ]; then /usr/local/sbin/btrfs-mksnapshot-rootfs; fi"; };
index 9be1b6a09144d0d38e3751ba57f80d0678c09bb8..01c7c6705becd268e74aa2c88b66d0968fb034e3 100644 (file)
@@ -15,6 +15,8 @@ install-local: btrfs-mksnapshot
         $(DESTDIR)$(PREFIX)/sbin
        install -p -o $(USER) -g $(GROUP) -m 755 btrfs-mksnapshot \
         $(DESTDIR)$(PREFIX)/sbin/btrfs-mksnapshot
+       install -p -o $(USER) -g $(GROUP) -m 755 btrfs-mksnapshot-rootfs \
+        $(DESTDIR)$(PREFIX)/sbin/btrfs-mksnapshot-rootfs
        install -d -o $(USER) -g $(GROUP) -m 755 \
         $(DESTDIR)/etc/apt/apt.conf.d
        install -p -o $(USER) -g $(GROUP) -m 644 06btrfs-mksnapshot \
diff --git a/btrfs/mksnapshot/btrfs-mksnapshot-rootfs b/btrfs/mksnapshot/btrfs-mksnapshot-rootfs
new file mode 100755 (executable)
index 0000000..798e608
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash -e
+#
+# btrfs-mksnapshot-rootfs -- Make snapshots of root filesystems ("/")
+# Copyright (c)2014 Alexander Barton (alex@barton.de)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+NAME=`basename "$0"`
+
+function Usage()
+{
+       echo "Usage: $NAME"; echo
+       exit 1
+}
+
+[ $# -eq 0 ] || Usage
+
+if [ -n "`fgrep ' / btrfs ' /etc/fstab 2>/dev/null`" ]; then
+       if [ -x /usr/local/sbin/btrfs-mksnapshot ]; then
+               /usr/local/sbin/btrfs-mksnapshot -1 / || exit 1
+       else
+               echo "\"/usr/local/sbin/btrfs-mksnapshot\" not executable, snapshot creation skipped."
+       fi
+else
+       echo "Root filesystem is not ot type \"btrfs\", snapshot creation skipped."
+fi
+exit 0