From de7360f26cc958695d915b080039b61cd4acd4f2 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Fri, 25 Apr 2014 10:54:43 +0200 Subject: [PATCH] Add btrfs-mksnapshot-rootfs script 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 | 2 +- btrfs/mksnapshot/Makefile | 2 ++ btrfs/mksnapshot/btrfs-mksnapshot-rootfs | 31 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 btrfs/mksnapshot/btrfs-mksnapshot-rootfs diff --git a/btrfs/mksnapshot/06btrfs-mksnapshot b/btrfs/mksnapshot/06btrfs-mksnapshot index 182570e..3b2e041 100644 --- a/btrfs/mksnapshot/06btrfs-mksnapshot +++ b/btrfs/mksnapshot/06btrfs-mksnapshot @@ -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"; }; diff --git a/btrfs/mksnapshot/Makefile b/btrfs/mksnapshot/Makefile index 9be1b6a..01c7c67 100644 --- a/btrfs/mksnapshot/Makefile +++ b/btrfs/mksnapshot/Makefile @@ -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 index 0000000..798e608 --- /dev/null +++ b/btrfs/mksnapshot/btrfs-mksnapshot-rootfs @@ -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 -- 2.39.2