diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2021-06-15 16:45:20 +0200 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2021-06-15 16:45:20 +0200 |
commit | b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8 (patch) | |
tree | daa3ef109d6f0b1dd7884622a2b2fba8c10e32cb /borg-family-0.2 | |
parent | 1ada10f44e2baf28823156c006c82a076c52f530 (diff) | |
download | borg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.tar.gz borg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.tar.bz2 borg-family-b9601cf46a75b373f6b6b902d7ac2be38ab2ffe8.zip |
borg-family_0.2-1
Diffstat (limited to 'borg-family-0.2')
32 files changed, 383 insertions, 0 deletions
diff --git a/borg-family-0.2/Makefile b/borg-family-0.2/Makefile new file mode 100644 index 0000000..2230ee9 --- /dev/null +++ b/borg-family-0.2/Makefile @@ -0,0 +1,27 @@ +PKGNAME=borg-family +VERSION=0.2 + +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.2/README b/borg-family-0.2/README new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/borg-family-0.2/README diff --git a/borg-family-0.2/debian/borg-family.config b/borg-family-0.2/debian/borg-family.config new file mode 100644 index 0000000..7483dd7 --- /dev/null +++ b/borg-family-0.2/debian/borg-family.config @@ -0,0 +1,5 @@ +#!/bin/sh -e +. /usr/share/debconf/confmodule +db_input critical borg-family/borg-repo || true +db_input critical borg-family/borg-repo2 || true +db_go diff --git a/borg-family-0.2/debian/borg-family.cron.daily b/borg-family-0.2/debian/borg-family.cron.daily new file mode 100644 index 0000000..d08f88a --- /dev/null +++ b/borg-family-0.2/debian/borg-family.cron.daily @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ -x /usr/sbin/bfrun ]; then + /usr/bin/systemd-inhibit --why="Prevent interrupting backup" /usr/sbin/bfrun +fi diff --git a/borg-family-0.2/debian/borg-family.docs b/borg-family-0.2/debian/borg-family.docs new file mode 100644 index 0000000..e845566 --- /dev/null +++ b/borg-family-0.2/debian/borg-family.docs @@ -0,0 +1 @@ +README diff --git a/borg-family-0.2/debian/borg-family.examples b/borg-family-0.2/debian/borg-family.examples new file mode 100644 index 0000000..e002ac5 --- /dev/null +++ b/borg-family-0.2/debian/borg-family.examples @@ -0,0 +1 @@ +doc/examples/envvars diff --git a/borg-family-0.2/debian/borg-family.init b/borg-family-0.2/debian/borg-family.init new file mode 100644 index 0000000..3b7b326 --- /dev/null +++ b/borg-family-0.2/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 should run bfrun from cron if not using systemd borg-family.timer" ;; +esac diff --git a/borg-family-0.2/debian/borg-family.manpages b/borg-family-0.2/debian/borg-family.manpages new file mode 100644 index 0000000..160e2fa --- /dev/null +++ b/borg-family-0.2/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.2/debian/borg-family.postinst b/borg-family-0.2/debian/borg-family.postinst new file mode 100644 index 0000000..e900217 --- /dev/null +++ b/borg-family-0.2/debian/borg-family.postinst @@ -0,0 +1,17 @@ +#!/bin/sh +set -e + +if [ "$1" = configure ]; then + . /usr/share/debconf/confmodule + unset BORG_REPO + for i in "" 2 + do + db_get borg-family/borg-repo$i && BORG_REPO="$RET" + ENVFILE=/etc/borg-family/envvars$i + [ -f "$ENVFILE" ] || install -m 644 /usr/share/doc/borg-family/examples/envvars "$ENVFILE" + [ -n "$BORG_REPO" ] && sed --in-place -e 's#^export BORG_REPO=.*$#export BORG_REPO="'$BORG_REPO'"#' -- "$ENVFILE" + done + db_stop +fi + +#DEBHELPER# diff --git a/borg-family-0.2/debian/borg-family.postrm b/borg-family-0.2/debian/borg-family.postrm new file mode 100644 index 0000000..cf11e70 --- /dev/null +++ b/borg-family-0.2/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 /etc/borg-family/envvars2 +fi + +#DEBHELPER# diff --git a/borg-family-0.2/debian/borg-family.service b/borg-family-0.2/debian/borg-family.service new file mode 100644 index 0000000..f6aab42 --- /dev/null +++ b/borg-family-0.2/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.2/debian/borg-family.substvars b/borg-family-0.2/debian/borg-family.substvars new file mode 100644 index 0000000..a595723 --- /dev/null +++ b/borg-family-0.2/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.2/debian/borg-family.templates b/borg-family-0.2/debian/borg-family.templates new file mode 100644 index 0000000..4c1a6c9 --- /dev/null +++ b/borg-family-0.2/debian/borg-family.templates @@ -0,0 +1,16 @@ +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. + +Template: borg-family/borg-repo2 +Type: string +Description: Second Borg repository URL: + Please set the second 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.2/debian/changelog b/borg-family-0.2/debian/changelog new file mode 100644 index 0000000..b88eba1 --- /dev/null +++ b/borg-family-0.2/debian/changelog @@ -0,0 +1,5 @@ +borg-family (0.2-1) UNRELEASED; urgency=medium + + * New upstream release. + + -- Ludovic Pouzenc <ludovic@pouzenc.fr> Tue, 15 Jun 2021 15:59:45 +0200 diff --git a/borg-family-0.2/debian/compat b/borg-family-0.2/debian/compat new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/borg-family-0.2/debian/compat @@ -0,0 +1 @@ +10 diff --git a/borg-family-0.2/debian/control b/borg-family-0.2/debian/control new file mode 100644 index 0000000..3ca323f --- /dev/null +++ b/borg-family-0.2/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.2/debian/debhelper-build-stamp b/borg-family-0.2/debian/debhelper-build-stamp new file mode 100644 index 0000000..e8dd97e --- /dev/null +++ b/borg-family-0.2/debian/debhelper-build-stamp @@ -0,0 +1 @@ +borg-family diff --git a/borg-family-0.2/debian/files b/borg-family-0.2/debian/files new file mode 100644 index 0000000..120b6c0 --- /dev/null +++ b/borg-family-0.2/debian/files @@ -0,0 +1,2 @@ +borg-family_0.2-1_all.deb admin optional +borg-family_0.2-1_amd64.buildinfo admin optional diff --git a/borg-family-0.2/debian/rules b/borg-family-0.2/debian/rules new file mode 100755 index 0000000..cbe925d --- /dev/null +++ b/borg-family-0.2/debian/rules @@ -0,0 +1,3 @@ +#!/usr/bin/make -f +%: + dh $@ diff --git a/borg-family-0.2/debian/source/format b/borg-family-0.2/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/borg-family-0.2/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/borg-family-0.2/doc/examples/envvars b/borg-family-0.2/doc/examples/envvars new file mode 100644 index 0000000..99f7139 --- /dev/null +++ b/borg-family-0.2/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.2/doc/man/bfenv.1 b/borg-family-0.2/doc/man/bfenv.1 new file mode 120000 index 0000000..080be00 --- /dev/null +++ b/borg-family-0.2/doc/man/bfenv.1 @@ -0,0 +1 @@ +bfrun.1
\ No newline at end of file diff --git a/borg-family-0.2/doc/man/bfrun.1 b/borg-family-0.2/doc/man/bfrun.1 new file mode 100644 index 0000000..efc42a7 --- /dev/null +++ b/borg-family-0.2/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.2/doc/man/bfwhat.1 b/borg-family-0.2/doc/man/bfwhat.1 new file mode 120000 index 0000000..080be00 --- /dev/null +++ b/borg-family-0.2/doc/man/bfwhat.1 @@ -0,0 +1 @@ +bfrun.1
\ No newline at end of file diff --git a/borg-family-0.2/src/etc/bfhooks b/borg-family-0.2/src/etc/bfhooks new file mode 100755 index 0000000..c7ce378 --- /dev/null +++ b/borg-family-0.2/src/etc/bfhooks @@ -0,0 +1,43 @@ +#!/bin/bash -e +mount_bind_rootfs() { + if ! mount | grep -q /rootfs; then + mkdir -p /rootfs + mount --bind / /rootfs + fi +} + +mount_efi() { + if ! mount | grep -q /boot/efi; then + mount /boot/efi + fi +} + +umount_bind_rootfs() { + if mount | grep -q /rootfs; then + umount /rootfs || lsof -n | grep /rootfs + rmdir /rootfs + fi +} + +umount_efi() { + if mount | grep -q /boot/efi; then + umount /boot/efi || lsof -n | grep /boot/efi + fi +} + +case $1 in + before) + echo "Start of backup: $2 to $BORG_REPO" + case $2 in + rootfs) apt-get clean || true; mount_bind_rootfs;; + boot-efi) mount_efi ;; + esac + ;; + after) + case $2 in + rootfs) umount_bind_rootfs ;; + boot-efi) umount_efi ;; + esac + echo "End of backup: $2 to $BORG_REPO" + ;; +esac diff --git a/borg-family-0.2/src/etc/confvars b/borg-family-0.2/src/etc/confvars new file mode 100644 index 0000000..4737195 --- /dev/null +++ b/borg-family-0.2/src/etc/confvars @@ -0,0 +1,4 @@ +# This file is used by bfenv and bfrun (bash scripts) +borg_init_opts=( -e repokey-blake2 --make-parent-dirs -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.2/src/etc/excludes.d/home b/borg-family-0.2/src/etc/excludes.d/home new file mode 100644 index 0000000..c7aead3 --- /dev/null +++ b/borg-family-0.2/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.2/src/etc/excludes.d/rootfs b/borg-family-0.2/src/etc/excludes.d/rootfs new file mode 100644 index 0000000..b61797b --- /dev/null +++ b/borg-family-0.2/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.2/src/sbin/bfenv b/borg-family-0.2/src/sbin/bfenv new file mode 100755 index 0000000..756ef62 --- /dev/null +++ b/borg-family-0.2/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.2/src/sbin/bfenv2 b/borg-family-0.2/src/sbin/bfenv2 new file mode 100755 index 0000000..6e5adeb --- /dev/null +++ b/borg-family-0.2/src/sbin/bfenv2 @@ -0,0 +1,31 @@ +#!/bin/bash +umask 0077 +source /etc/borg-family/confvars +source /etc/borg-family/envvars2 +PATH="/etc/borg-family:$PATH" + +if [ \! -r /etc/borg-family/passphrase2 ]; then + echo "No passphrase2 (repokey) found, creating a new one" >&2 + touch /etc/borg-family/passphrase2 + chmod 600 /etc/borg-family/passphrase2 + pwgen 32 1 >> /etc/borg-family/passphrase2 + ls -l /etc/borg-family/passphrase2 >&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 + +LANG=C borg init "${borg_init_opts[@]}" 2>&1 | grep -vE '^A repository already exists' >&2 + +if ! borg list > /dev/null; 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.2/src/sbin/bfrun b/borg-family-0.2/src/sbin/bfrun new file mode 100755 index 0000000..b0f80dd --- /dev/null +++ b/borg-family-0.2/src/sbin/bfrun @@ -0,0 +1,32 @@ +#!/bin/bash +for e in bfenv bfenv2 +do + source $e + 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 +done diff --git a/borg-family-0.2/src/sbin/bfwhat b/borg-family-0.2/src/sbin/bfwhat new file mode 100755 index 0000000..bf9cf4d --- /dev/null +++ b/borg-family-0.2/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 |