blob: 4d2cfb2013846c73b49b5965abf74ddc418551e9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
|