From 1ada10f44e2baf28823156c006c82a076c52f530 Mon Sep 17 00:00:00 2001
From: Ludovic Pouzenc <ludovic@pouzenc.fr>
Date: Fri, 15 Jan 2021 23:17:34 +0100
Subject: borg-family_0.1-1

---
 .gitignore                                   | 13 +++++++
 borg-family-0.1/Makefile                     | 27 +++++++++++++++
 borg-family-0.1/README                       |  0
 borg-family-0.1/debian/borg-family.config    |  4 +++
 borg-family-0.1/debian/borg-family.docs      |  1 +
 borg-family-0.1/debian/borg-family.examples  |  1 +
 borg-family-0.1/debian/borg-family.init      | 17 +++++++++
 borg-family-0.1/debian/borg-family.manpages  |  3 ++
 borg-family-0.1/debian/borg-family.postinst  | 15 ++++++++
 borg-family-0.1/debian/borg-family.postrm    | 10 ++++++
 borg-family-0.1/debian/borg-family.service   | 14 ++++++++
 borg-family-0.1/debian/borg-family.substvars |  2 ++
 borg-family-0.1/debian/borg-family.templates |  8 +++++
 borg-family-0.1/debian/borg-family.timer     | 10 ++++++
 borg-family-0.1/debian/changelog             |  5 +++
 borg-family-0.1/debian/compat                |  1 +
 borg-family-0.1/debian/control               | 14 ++++++++
 borg-family-0.1/debian/debhelper-build-stamp |  1 +
 borg-family-0.1/debian/files                 |  2 ++
 borg-family-0.1/debian/rules                 |  3 ++
 borg-family-0.1/debian/source/format         |  1 +
 borg-family-0.1/doc/examples/envvars         | 10 ++++++
 borg-family-0.1/doc/man/bfenv.1              |  1 +
 borg-family-0.1/doc/man/bfrun.1              | 52 ++++++++++++++++++++++++++++
 borg-family-0.1/doc/man/bfwhat.1             |  1 +
 borg-family-0.1/src/etc/bfhooks              | 27 +++++++++++++++
 borg-family-0.1/src/etc/confvars             |  5 +++
 borg-family-0.1/src/etc/excludes.d/home      |  4 +++
 borg-family-0.1/src/etc/excludes.d/rootfs    |  5 +++
 borg-family-0.1/src/sbin/bfenv               | 31 +++++++++++++++++
 borg-family-0.1/src/sbin/bfrun               | 29 ++++++++++++++++
 borg-family-0.1/src/sbin/bfwhat              | 24 +++++++++++++
 32 files changed, 341 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 borg-family-0.1/Makefile
 create mode 100644 borg-family-0.1/README
 create mode 100644 borg-family-0.1/debian/borg-family.config
 create mode 100644 borg-family-0.1/debian/borg-family.docs
 create mode 100644 borg-family-0.1/debian/borg-family.examples
 create mode 100644 borg-family-0.1/debian/borg-family.init
 create mode 100644 borg-family-0.1/debian/borg-family.manpages
 create mode 100644 borg-family-0.1/debian/borg-family.postinst
 create mode 100644 borg-family-0.1/debian/borg-family.postrm
 create mode 100644 borg-family-0.1/debian/borg-family.service
 create mode 100644 borg-family-0.1/debian/borg-family.substvars
 create mode 100644 borg-family-0.1/debian/borg-family.templates
 create mode 100644 borg-family-0.1/debian/borg-family.timer
 create mode 100644 borg-family-0.1/debian/changelog
 create mode 100644 borg-family-0.1/debian/compat
 create mode 100644 borg-family-0.1/debian/control
 create mode 100644 borg-family-0.1/debian/debhelper-build-stamp
 create mode 100644 borg-family-0.1/debian/files
 create mode 100755 borg-family-0.1/debian/rules
 create mode 100644 borg-family-0.1/debian/source/format
 create mode 100644 borg-family-0.1/doc/examples/envvars
 create mode 120000 borg-family-0.1/doc/man/bfenv.1
 create mode 100644 borg-family-0.1/doc/man/bfrun.1
 create mode 120000 borg-family-0.1/doc/man/bfwhat.1
 create mode 100755 borg-family-0.1/src/etc/bfhooks
 create mode 100644 borg-family-0.1/src/etc/confvars
 create mode 100644 borg-family-0.1/src/etc/excludes.d/home
 create mode 100644 borg-family-0.1/src/etc/excludes.d/rootfs
 create mode 100755 borg-family-0.1/src/sbin/bfenv
 create mode 100755 borg-family-0.1/src/sbin/bfrun
 create mode 100755 borg-family-0.1/src/sbin/bfwhat

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2def6f9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+borg-family-*/debian/borg-family.postinst.debhelper
+borg-family-*/debian/borg-family
+borg-family-*/debian/.debhelper
+borg-family-*/debian/borg-family.prerm.debhelper
+borg-family-*/debian/borg-family.postrm.debhelper
+borg-family-*/debian/copyright
+borg-family_*.orig.tar.gz
+borg-family_*.debian.tar.xz
+borg-family_*_amd64.buildinfo
+borg-family_*.dsc
+borg-family_*_all.deb
+borg-family_*_amd64.build
+borg-family_*_amd64.changes
diff --git a/borg-family-0.1/Makefile b/borg-family-0.1/Makefile
new file mode 100644
index 0000000..ff88bdd
--- /dev/null
+++ b/borg-family-0.1/Makefile
@@ -0,0 +1,27 @@
+PKGNAME=borg-family
+VERSION=0.1
+
+INSTALL=install
+INSTALL_PROGRAM=$(INSTALL)
+INSTALL_DATA=${INSTALL} -m 644
+confdir=/etc/${PKGNAME}
+sbindir=/usr/sbin
+
+all:
+
+deb:
+	cd .. && tar -czf ${PKGNAME}_${VERSION}.orig.tar.gz --exclude debian ${PKGNAME}-${VERSION}
+	debuild -us -uc
+
+install:
+	$(INSTALL) -d $(DESTDIR)$(sbindir)
+	$(INSTALL) -d $(DESTDIR)$(confdir)/excludes.d
+	$(INSTALL_PROGRAM) src/sbin/bfenv            $(DESTDIR)$(sbindir)
+	$(INSTALL_PROGRAM) src/sbin/bfrun            $(DESTDIR)$(sbindir)
+	$(INSTALL_PROGRAM) src/sbin/bfwhat           $(DESTDIR)$(sbindir)
+	$(INSTALL_PROGRAM) src/etc/bfhooks           $(DESTDIR)$(confdir)
+	$(INSTALL_DATA)    src/etc/confvars          $(DESTDIR)$(confdir)
+	$(INSTALL_DATA)    src/etc/excludes.d/home   $(DESTDIR)$(confdir)/excludes.d
+	$(INSTALL_DATA)    src/etc/excludes.d/rootfs $(DESTDIR)$(confdir)/excludes.d
+
+.PHONY: all deb install
diff --git a/borg-family-0.1/README b/borg-family-0.1/README
new file mode 100644
index 0000000..e69de29
diff --git a/borg-family-0.1/debian/borg-family.config b/borg-family-0.1/debian/borg-family.config
new file mode 100644
index 0000000..d0e4f26
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.config
@@ -0,0 +1,4 @@
+#!/bin/sh -e
+. /usr/share/debconf/confmodule
+db_input critical borg-family/borg-repo || true
+db_go
diff --git a/borg-family-0.1/debian/borg-family.docs b/borg-family-0.1/debian/borg-family.docs
new file mode 100644
index 0000000..e845566
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.docs
@@ -0,0 +1 @@
+README
diff --git a/borg-family-0.1/debian/borg-family.examples b/borg-family-0.1/debian/borg-family.examples
new file mode 100644
index 0000000..e002ac5
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.examples
@@ -0,0 +1 @@
+doc/examples/envvars
diff --git a/borg-family-0.1/debian/borg-family.init b/borg-family-0.1/debian/borg-family.init
new file mode 100644
index 0000000..72e9267
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.init
@@ -0,0 +1,17 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          borg-family
+# Required-Start:    $network $local_fs $syslog
+# Required-Stop:     $local_fs $syslog
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: borg-family backup scripts
+# Description:       Makes Borg running periodically to backup computers to a remote server
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+case "$1" in
+  start|stop|restart|reload|status|force-reload)
+    log_action_msg "This is a stub, you shuld run bfrun from cron if not using systemd borg-family.timer" ;;
+esac
diff --git a/borg-family-0.1/debian/borg-family.manpages b/borg-family-0.1/debian/borg-family.manpages
new file mode 100644
index 0000000..160e2fa
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.manpages
@@ -0,0 +1,3 @@
+doc/man/bfenv.1
+doc/man/bfrun.1
+doc/man/bfwhat.1
diff --git a/borg-family-0.1/debian/borg-family.postinst b/borg-family-0.1/debian/borg-family.postinst
new file mode 100644
index 0000000..5bf8c69
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.postinst
@@ -0,0 +1,15 @@
+#!/bin/sh
+set -e
+
+EVFILE=/etc/borg-family/envvars
+
+if [ "$1" = configure ]; then
+	. /usr/share/debconf/confmodule
+	unset BORG_REPO
+	db_get borg-family/borg-repo && BORG_REPO="$RET"
+	db_stop
+	[ -f "$EVFILE" ] || install -m 644 /usr/share/doc/borg-family/examples/envvars "$EVFILE"
+	[ -n "$BORG_REPO" ] && sed --in-place -e 's#^export BORG_REPO=.*$#export BORG_REPO="'$BORG_REPO'"#' -- "$EVFILE"
+fi
+
+#DEBHELPER#
diff --git a/borg-family-0.1/debian/borg-family.postrm b/borg-family-0.1/debian/borg-family.postrm
new file mode 100644
index 0000000..5ae54c6
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.postrm
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -e
+
+if [ "$1" = "purge" ]; then
+    . /usr/share/debconf/confmodule
+    db_purge
+    rm -f /etc/borg-family/envvars
+fi
+
+#DEBHELPER#
diff --git a/borg-family-0.1/debian/borg-family.service b/borg-family-0.1/debian/borg-family.service
new file mode 100644
index 0000000..f6aab42
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Makes Borg running periodically to backup computers to a remote server
+Wants=default.target network-online.target
+ConditionACPower=true
+
+[Service]
+ExecStart=/usr/bin/systemd-inhibit --why="Prevent interrupting backup" /usr/sbin/bfrun 
+Restart=no
+# Lower CPU and I/O priority.
+Nice=19
+CPUSchedulingPolicy=batch
+IOSchedulingClass=best-effort
+IOSchedulingPriority=7
+IOWeight=100
diff --git a/borg-family-0.1/debian/borg-family.substvars b/borg-family-0.1/debian/borg-family.substvars
new file mode 100644
index 0000000..a595723
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.substvars
@@ -0,0 +1,2 @@
+misc:Depends=debconf (>= 0.5) | debconf-2.0
+misc:Pre-Depends=
diff --git a/borg-family-0.1/debian/borg-family.templates b/borg-family-0.1/debian/borg-family.templates
new file mode 100644
index 0000000..b17ce60
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.templates
@@ -0,0 +1,8 @@
+Template: borg-family/borg-repo
+Type: string
+Description: Borg repository URL:
+ Please set the backup destination.
+ .
+ It will be exported to BORG_REPO by bfrun for borg commands.
+ Could be 'ssh://user@host:port/abspath/to/repo', or 'user@host:relpath/to/repo', see man borg.
+
diff --git a/borg-family-0.1/debian/borg-family.timer b/borg-family-0.1/debian/borg-family.timer
new file mode 100644
index 0000000..14a848a
--- /dev/null
+++ b/borg-family-0.1/debian/borg-family.timer
@@ -0,0 +1,10 @@
+[Unit]
+Description=Run borg-family backup
+
+[Timer]
+OnCalendar=daily
+Persistent=true
+
+[Install]
+WantedBy=timers.target
+
diff --git a/borg-family-0.1/debian/changelog b/borg-family-0.1/debian/changelog
new file mode 100644
index 0000000..e2329ed
--- /dev/null
+++ b/borg-family-0.1/debian/changelog
@@ -0,0 +1,5 @@
+borg-family (0.1-1) UNRELEASED; urgency=medium
+
+  * Initial release.
+
+ -- Ludovic Pouzenc <ludovic@pouzenc.fr>  Sat, 28 Nov 2020 17:07:53 +0100
diff --git a/borg-family-0.1/debian/compat b/borg-family-0.1/debian/compat
new file mode 100644
index 0000000..f599e28
--- /dev/null
+++ b/borg-family-0.1/debian/compat
@@ -0,0 +1 @@
+10
diff --git a/borg-family-0.1/debian/control b/borg-family-0.1/debian/control
new file mode 100644
index 0000000..3ca323f
--- /dev/null
+++ b/borg-family-0.1/debian/control
@@ -0,0 +1,14 @@
+Source: borg-family
+Maintainer: Ludovic Pouzenc <ludovic@pouzenc.fr>
+Section: admin
+Priority: optional
+Standards-Version: 4.3.0
+Build-Depends: debhelper (>= 10)
+
+Package: borg-family
+Architecture: all
+Depends: bash (>= 2.0), borgbackup (>= 1.0), coreutils (>= 4.0), debconf, gawk, openssh-client, pwgen (>= 2.0), sed (>= 4.0), util-linux (>= 2.0), ${misc:Depends}
+Description: Makes Borg running periodically to backup computers to a remote server
+ borg-family ease the backup automation configuration around Borg
+ in small environnements, like backuping some computers to a remote
+ family server.
diff --git a/borg-family-0.1/debian/debhelper-build-stamp b/borg-family-0.1/debian/debhelper-build-stamp
new file mode 100644
index 0000000..e8dd97e
--- /dev/null
+++ b/borg-family-0.1/debian/debhelper-build-stamp
@@ -0,0 +1 @@
+borg-family
diff --git a/borg-family-0.1/debian/files b/borg-family-0.1/debian/files
new file mode 100644
index 0000000..225c048
--- /dev/null
+++ b/borg-family-0.1/debian/files
@@ -0,0 +1,2 @@
+borg-family_0.1-1_all.deb admin optional
+borg-family_0.1-1_amd64.buildinfo admin optional
diff --git a/borg-family-0.1/debian/rules b/borg-family-0.1/debian/rules
new file mode 100755
index 0000000..cbe925d
--- /dev/null
+++ b/borg-family-0.1/debian/rules
@@ -0,0 +1,3 @@
+#!/usr/bin/make -f
+%:
+	dh $@
diff --git a/borg-family-0.1/debian/source/format b/borg-family-0.1/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/borg-family-0.1/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/borg-family-0.1/doc/examples/envvars b/borg-family-0.1/doc/examples/envvars
new file mode 100644
index 0000000..99f7139
--- /dev/null
+++ b/borg-family-0.1/doc/examples/envvars
@@ -0,0 +1,10 @@
+# To consult or restore backups, just load this file in a root shell environnement variables with:
+#  source /etc/borg-family/envvars
+# Then use commands like:
+#  borg list
+#  mkdir /mnt/restore
+#  borg mount ::somehostname-rootfs-2020-08-15 /mnt/restore
+#  cp -ai /mnt/restore/rootfs/etc/veryimportantfile /etc/
+export BORG_RSH="ssh -i /etc/borg-family/id_rsa_borg"
+export BORG_PASSCOMMAND="cat /etc/borg-family/passphrase"
+export BORG_REPO="ssh://user@host:port/path/to/repo"
diff --git a/borg-family-0.1/doc/man/bfenv.1 b/borg-family-0.1/doc/man/bfenv.1
new file mode 120000
index 0000000..080be00
--- /dev/null
+++ b/borg-family-0.1/doc/man/bfenv.1
@@ -0,0 +1 @@
+bfrun.1
\ No newline at end of file
diff --git a/borg-family-0.1/doc/man/bfrun.1 b/borg-family-0.1/doc/man/bfrun.1
new file mode 100644
index 0000000..efc42a7
--- /dev/null
+++ b/borg-family-0.1/doc/man/bfrun.1
@@ -0,0 +1,52 @@
+.TH BORG-FAMILY 1 local
+.SH NAME
+bfrun, bfwhat, bfenv \- scripts to run Borg to backup your computers
+.SH SYNOPSIS
+.ll +8
+.B bfrun
+.ll -8
+.br
+.SH DESCRIPTION
+.I bfrun
+invokes
+.I bfenv
+then
+.I bfwhat
+to check repository availability and list local mount points to backup.
+.SH OPTIONS
+.ll +8
+.B No options.
+See /etc/borg-family
+.ll -8
+.SH "ENVIRONMENT"
+.B bfrun
+loads /etc/borg-family/envvars for Borg and /etc/borg-family/confvars for itself.
+.SH "SEE ALSO"
+borgbackup(1)
+.SH CAVEATS
+Poor manpage.
+.SH BUGS
+Reports them to 
+.BR "<ludovic@pouzenc.fr>"
+.SH "COPYRIGHT NOTICE"
+Copyright \(co 2020 Ludovic Pouzenc <ludovic@pouzenc.fr>
+.PP
+Permission is granted to make and distribute verbatim copies of
+this manual provided the copyright notice and this permission notice
+are preserved on all copies.
+.ig
+Permission is granted to process this file through troff and print the
+results, provided the printed document carries copying permission
+notice identical to this one except for the removal of this paragraph
+(this paragraph not being relevant to the printed manual).
+..
+.PP
+Permission is granted to copy and distribute modified versions of this
+manual under the conditions for verbatim copying, provided that the entire
+resulting derived work is distributed under the terms of a permission
+notice identical to this one.
+.PP
+Permission is granted to copy and distribute translations of this manual
+into another language, under the above conditions for modified versions,
+except that this permission notice may be stated in a translation approved
+by the Foundation.
diff --git a/borg-family-0.1/doc/man/bfwhat.1 b/borg-family-0.1/doc/man/bfwhat.1
new file mode 120000
index 0000000..080be00
--- /dev/null
+++ b/borg-family-0.1/doc/man/bfwhat.1
@@ -0,0 +1 @@
+bfrun.1
\ No newline at end of file
diff --git a/borg-family-0.1/src/etc/bfhooks b/borg-family-0.1/src/etc/bfhooks
new file mode 100755
index 0000000..5b6b204
--- /dev/null
+++ b/borg-family-0.1/src/etc/bfhooks
@@ -0,0 +1,27 @@
+#!/bin/bash -e
+mount_bind_rootfs() {
+	if ! mount | grep -q /rootfs; then
+		mkdir -p /rootfs
+		mount --bind / /rootfs
+	fi
+}
+
+umount_bind_rootfs() {
+	if mount | grep -q /rootfs; then
+		umount /rootfs || lsof -n | grep /rootfs
+		rmdir /rootfs
+	fi
+}
+
+case $1 in
+	before)
+		case $2 in
+			rootfs) apt-get clean || true; mount_bind_rootfs;;
+		esac
+		;;
+	after)
+		case $2 in
+			rootfs) umount_bind_rootfs ;;
+		esac
+		;;
+esac
diff --git a/borg-family-0.1/src/etc/confvars b/borg-family-0.1/src/etc/confvars
new file mode 100644
index 0000000..f737648
--- /dev/null
+++ b/borg-family-0.1/src/etc/confvars
@@ -0,0 +1,5 @@
+# This file is used by bfenv and bfrun (bash scripts)
+borg_init_opts=( -e repokey-blake2 --make-parent-dirs -v )
+borg_check_opts=( --last $((1+$(bfwhat | wc -l) )) -v )
+borg_create_opts=( --one-file-system --compression zstd --exclude-caches --exclude-if-present=NOBACKUPDIR.TAG --keep-exclude-tags --list --filter=AMEi-x --stats --show-rc -v )
+quiet=0
diff --git a/borg-family-0.1/src/etc/excludes.d/home b/borg-family-0.1/src/etc/excludes.d/home
new file mode 100644
index 0000000..c7aead3
--- /dev/null
+++ b/borg-family-0.1/src/etc/excludes.d/home
@@ -0,0 +1,4 @@
+**/.cache/*
+/home/*/.mozilla/**/datareporting
+/home/*/.thunderbird/**/global-messages-db.sqlite
+/home/*/.thunderbird/**/ImapMail
diff --git a/borg-family-0.1/src/etc/excludes.d/rootfs b/borg-family-0.1/src/etc/excludes.d/rootfs
new file mode 100644
index 0000000..b61797b
--- /dev/null
+++ b/borg-family-0.1/src/etc/excludes.d/rootfs
@@ -0,0 +1,5 @@
+/rootfs/var/cache/apt/*
+**/.cache/*
+/rootfs/home/*/.mozilla/**/datareporting
+/rootfs/home/*/.thunderbird/**/global-messages-db.sqlite
+/rootfs/home/*/.thunderbird/**/ImapMail
diff --git a/borg-family-0.1/src/sbin/bfenv b/borg-family-0.1/src/sbin/bfenv
new file mode 100755
index 0000000..756ef62
--- /dev/null
+++ b/borg-family-0.1/src/sbin/bfenv
@@ -0,0 +1,31 @@
+#!/bin/bash
+umask 0077
+source /etc/borg-family/confvars
+source /etc/borg-family/envvars
+PATH="/etc/borg-family:$PATH"
+
+if [ \! -r /etc/borg-family/passphrase ]; then
+	echo "No passphrase (repokey) found, creating a new one" >&2
+	touch /etc/borg-family/passphrase
+	chmod 600 /etc/borg-family/passphrase
+	pwgen 32 1 >> /etc/borg-family/passphrase
+	ls -l /etc/borg-family/passphrase >&2
+	echo "You NEED to store it in a password manager to be able to restore backups" >&2
+fi
+
+if [ \! -r /etc/borg-family/id_rsa_borg ]; then
+	echo "No SSH key found, creating a new one" >&2
+	ssh-keygen -N "" -C "$(id -un)_borg@$(hostname)" -f /etc/borg-family/id_rsa_borg \
+		&& cat /etc/borg-family/id_rsa_borg.pub
+fi
+
+borg init "${borg_init_opts[@]}" 2>&1 | grep -vE '^A repository already exists' >&2
+
+if ! borg check "${borg_check_opts[@]}"; then
+	echo "Showing BORG_* env variables (see /etc/borg-family/envvars) :" >&2
+	env | grep ^BORG_ >&2
+	echo "End of BORG_* env variables" >&2
+	echo >&2
+	echo "Can't access to or check the borg repository, exiting, no backup made" >&2
+	exit 1
+fi
diff --git a/borg-family-0.1/src/sbin/bfrun b/borg-family-0.1/src/sbin/bfrun
new file mode 100755
index 0000000..c02187a
--- /dev/null
+++ b/borg-family-0.1/src/sbin/bfrun
@@ -0,0 +1,29 @@
+#!/bin/bash
+source bfenv
+bfwhat | while IFS=' ' read -r mpe dev; do
+	mp=$(echo -e "$mpe")              # mp: interpret escapings that may be present in /proc/mounts (\040 for space...)
+	name=${mp// /_};                  # name: replace space by underscore
+	name=${mp//\//-}; name=${name/-/} # name: replace slash by dash, remove the leading one
+	if [[ "$mp $name $dev" =~ "--" || "$mp $name $dev" =~ ".." || "$mp $name $dev" =~ "[|&;()<>]" ]]; then
+		echo "Skipping $mpe because of shell unsafe characters" >&2
+		continue
+	fi
+
+	comment=$(blkid -- "$dev")
+	if [ -r "/etc/borg-family/excludes.d/$name" ]; then
+		runtime_args=( --comment="$comment" --exclude-from="/etc/borg-family/excludes.d/$name" )
+	else	
+		runtime_args=( --comment="$comment" )
+	fi
+
+	bfhooks before "$name" && \
+	borg create "${runtime_args[@]}" "${borg_create_opts[@]}" "::{hostname}-$name-{now:%Y-%m-%d}" "$mp"
+	rc1=$?
+	bfhooks after "$name"
+	rc2=$?
+	if [ "$rc1" -ne 0 -o "$rc2" -ne 0 ]; then
+		echo "Errors during $name backup, return codes $rc1 (bfhook before && borg create) and $rc2 (bfhook after)" >&2
+	else
+		[ "x$quiet" == "x1" ] || echo "Success for $name backup"
+	fi
+done
diff --git a/borg-family-0.1/src/sbin/bfwhat b/borg-family-0.1/src/sbin/bfwhat
new file mode 100755
index 0000000..bf9cf4d
--- /dev/null
+++ b/borg-family-0.1/src/sbin/bfwhat
@@ -0,0 +1,24 @@
+#!/bin/bash
+what-from-proc-mounts() {
+	# Special case for "/", show it as /rootfs (see hook_* files). Helps saving initial /dev nodes files behind udev
+	awk '( $2 == "/" ) { print "/rootfs",$1 }' /proc/mounts
+
+	# Backup all non "/", non-removable, mounted filesystems which device is also shown in /sys/block
+	tmp=$(mktemp)
+	grep 0 /sys/block/*/removable | sed -e 's#^/sys/block#^/dev#' -e 's#/removable:0$##' >> "$tmp"
+	grep -Ef "$tmp" /proc/mounts | awk '( $2 !~ /^\/(rootfs|$)/ ) { print $2,$1 }'
+	rm -- "$tmp"
+}
+
+if [ -r /etc/borg-family/what.override ]; then
+	cat /etc/borg-family/what.override
+else
+	if [ -r /etc/borg-family/what.include ]; then
+		cat /etc/borg-family/what.include
+	fi
+	if [ -r /etc/borg-family/what.exclude ]; then
+		what-from-proc-mounts | grep -vEf /etc/borg-family/what.exclude
+	else
+		what-from-proc-mounts
+	fi
+fi
-- 
cgit v1.2.3