summaryrefslogtreecommitdiff
path: root/resteasy/libexec/resteasy-run-backup
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2020-02-25 19:42:07 +0100
committerJakob Odersky <jakob@odersky.com>2020-02-25 20:08:31 +0100
commit595131b8e3ffe99e9187c7adb5e73e922bd931e1 (patch)
treee2ce6d110858d8077517b602c33637ec704a1ad5 /resteasy/libexec/resteasy-run-backup
downloadresteasy-595131b8e3ffe99e9187c7adb5e73e922bd931e1.tar.gz
resteasy-595131b8e3ffe99e9187c7adb5e73e922bd931e1.tar.bz2
resteasy-595131b8e3ffe99e9187c7adb5e73e922bd931e1.zip
Initial commit
Diffstat (limited to 'resteasy/libexec/resteasy-run-backup')
-rwxr-xr-xresteasy/libexec/resteasy-run-backup74
1 files changed, 74 insertions, 0 deletions
diff --git a/resteasy/libexec/resteasy-run-backup b/resteasy/libexec/resteasy-run-backup
new file mode 100755
index 0000000..4d2cfb2
--- /dev/null
+++ b/resteasy/libexec/resteasy-run-backup
@@ -0,0 +1,74 @@
+#!/bin/bash
+USAGE=""
+
+# shellcheck source=resteasy-helper.sh
+source "$(resteasy --exec-path)/resteasy-helper.sh"
+
+set -o errexit
+set -o nounset
+
+[[ "$#" -eq 0 ]] || die_with_usage "too many arguments"
+[[ $EUID -eq 0 ]] || die "must be root"
+
+failed() {
+ log_status "errors encountered during backup"
+}
+trap failed EXIT
+
+borg --version
+
+# location of the mounted borg repository
+export BORG_REPO="$RESTEASY_MOUNT_POINT/borgbackup/$HOSTNAME"
+
+# set some environment variables to prevent borg from asking interactive questions
+export BORG_RELOCATED_REPO_ACCESS_IS_OK=no # relocated repos aren't cache-friendly
+export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=no
+export BORG_PASSCOMMAND="cat /etc/resteasy"
+
+# backup the system into an archive named after
+# the machine this script is currently running on
+log_status "starting backup"
+borg create \
+ --verbose \
+ --filter AME \
+ --list \
+ --stats \
+ --show-rc \
+ --compression lz4 \
+ --exclude-caches \
+ --exclude '/var/cache/' \
+ --exclude '/var/tmp/' \
+ --exclude '/root/.cache/' \
+ --exclude '/var/lib/docker/devicemapper/' \
+ --exclude '/home/*/.cache/' \
+ --exclude '/home/*/.local/share/Steam' \
+ ::'{hostname}-{now}' \
+ /etc \
+ /home \
+ /root \
+ /srv \
+ /usr/local \
+ /var
+
+# unnecessary, but just to be extra sure that data has made it onto disk
+sync
+
+log_status "pruning repository"
+
+# Use the `prune` subcommand to maintain archives of THIS machine. The
+# '{hostname}-' prefix is very important to limit prune's operation to this
+# machine's archives and not apply to other machines' archives too
+borg prune \
+ --list \
+ --prefix '{hostname}-' \
+ --show-rc \
+ --keep-daily 7 \
+ --keep-weekly 4 \
+ --keep-monthly 12 \
+ --keep-yearly 10
+
+borg check
+
+log_status "backup completed successfully"
+trap - EXIT
+