Skip to content

Commit ce27e1f

Browse files
committed
Updated to config v2
1 parent 1912664 commit ce27e1f

22 files changed

+947
-359
lines changed

.goreleaser.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,24 @@ nfpms:
153153
postinstall: "contrib/posix/post-install.sh"
154154
contents:
155155
- { type: config, src: contrib/posix/profiles.conf, dst: /etc/resticprofile/profiles.conf.dist }
156+
- { type: config, src: contrib/posix/conf.d/backup.conf, dst: /etc/resticprofile/conf.d/backup.conf.dist }
156157
- { type: config, src: contrib/posix/conf.d/check.conf, dst: /etc/resticprofile/conf.d/check.conf.dist }
157158
- { type: config, src: contrib/posix/conf.d/hooks.conf, dst: /etc/resticprofile/conf.d/hooks.conf.dist }
158159
- { type: config, src: contrib/posix/conf.d/metrics.conf, dst: /etc/resticprofile/conf.d/metrics.conf.dist }
159160
- { type: config, src: contrib/posix/conf.d/prune.conf, dst: /etc/resticprofile/conf.d/prune.conf.dist }
160-
- { type: config, src: contrib/posix/conf.d/repository.conf, dst: /etc/resticprofile/conf.d/repository.conf.dist }
161+
- { type: config, src: contrib/posix/conf.d/z_overrides.conf, dst: /etc/resticprofile/conf.d/z_overrides.conf.dist }
161162
- { type: config, src: contrib/posix/profiles.d/fs-snapshot.yaml.sample, dst: /etc/resticprofile/profiles.d/fs-snapshot.yaml.sample }
162-
- { type: config, src: contrib/posix/profiles.d/system.toml, dst: /etc/resticprofile/profiles.d/system.toml.dist }
163+
- { type: config, src: contrib/posix/profiles.d/minimal.conf.sample, dst: /etc/resticprofile/profiles.d/minimal.conf.sample }
164+
- { type: config, src: contrib/posix/profiles.d/minimal.yaml.sample, dst: /etc/resticprofile/profiles.d/minimal.yaml.sample }
165+
- { type: config, src: contrib/posix/profiles.d/system.conf, dst: /etc/resticprofile/profiles.d/system.conf.dist }
166+
- { type: config, src: contrib/posix/repository.d/default.conf, dst: /etc/resticprofile/repository.d/default.conf.dist }
167+
- { type: config, src: contrib/posix/repository.d/other.conf.sample, dst: /etc/resticprofile/repository.d/other.conf.sample }
168+
- { type: config, src: contrib/posix/templates/default-host.conf, dst: /etc/resticprofile/templates/default-host.conf.dist }
169+
- { type: config, src: contrib/posix/templates/default-tags.conf, dst: /etc/resticprofile/templates/default-tags.conf.dist }
163170
- { type: config, src: contrib/posix/templates/systemd.timer.in, dst: /etc/resticprofile/templates/systemd.timer.in.dist }
164171
- { type: config, src: contrib/posix/templates/systemd.unit.in, dst: /etc/resticprofile/templates/systemd.unit.in.dist }
165-
- src: contrib/systemd/resticprofile-send-error.sh
172+
- src: contrib/posix/resticprofile-send-error.rc
173+
dst: /etc/resticprofile/resticprofile-send-error.rc.dist
174+
- src: contrib/notification-scripts/resticprofile-send-error.sh
166175
dst: /usr/local/bin/resticprofile-send-error
167-
file_info: { mode: 0640, owner: root, group: root }
176+
file_info: { mode: 0755, owner: root, group: root }

contrib/notification-scripts/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Usage:
1515
resticprofile-send-error.sh [options] user1@domain user2@domain ...
1616
Options:
1717
-s Only send mail when operating on schedule (RESTICPROFILE_ON_SCHEDULE=1)
18+
-o name,.. Only send mail when PROFILE_NAME is in the list of specified names
1819
-c command Set the profile command (instead of PROFILE_COMMAND)
1920
-n name Set the profile name (instead of PROFILE_NAME)
2021
-p Print mail to stdout instead of sending it

contrib/notification-scripts/resticprofile-send-error.sh

+22-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ help() {
77
Usage $1 [options] user1@domain user2@domain ...
88
Options:
99
-s Only send mail when operating on schedule (RESTICPROFILE_ON_SCHEDULE=1)
10+
-o name,.. Only send mail when PROFILE_COMMAND is in the list of specified names
1011
-c command Set the profile command (instead of PROFILE_COMMAND)
1112
-n name Set the profile name (instead of PROFILE_NAME)
1213
-p Print mail to stdout instead of sending it
@@ -17,9 +18,11 @@ HELP
1718
# Parse CLI args
1819
FORCE_SENDING=0
1920
SEND_COMMAND=""
20-
while getopts 'c:fhn:ps' flag ; do
21+
LIMIT_COMMAND_NAMES=""
22+
while getopts 'c:fhn:o:ps' flag ; do
2123
case "${flag}" in
2224
c) PROFILE_COMMAND="${OPTARG}" ;;
25+
o) LIMIT_COMMAND_NAMES="${OPTARG}" ;;
2326
f) FORCE_SENDING=1 ;;
2427
n) PROFILE_NAME="${OPTARG}" ;;
2528
p) SEND_COMMAND="cat -" ;;
@@ -51,14 +54,14 @@ RC_FILE="/etc/resticprofile/$(basename "$0").rc}"
5154
[[ -f "${RC_FILE}" ]] && source "${RC_FILE}"
5255

5356
main() {
54-
if [[ -n "${PROFILE_NAME}" || "${FORCE_SENDING}" == "1" ]] ; then
57+
if can_send ; then
5558
if [[ -n "${DETAILS_COMMAND}" ]] ; then
5659
DETAILS_COMMAND_RESULT="$(${DETAILS_COMMAND})"
5760
fi
5861

5962
for email in "$@" "${MAIL_TO}" ; do
6063
if [[ "${email}" =~ ^[a-zA-Z0-9_.%+-]+@[a-zA-Z0-9_]+[a-zA-Z0-9_.-]+$ ]] ; then
61-
send_mail "${email}" || echo "Failed sending to \"${email}\""
64+
send_mail "${email}" || echo "Failed sending to \"${email}\" using '${SEND_COMMAND}' exit code $?"
6265
elif [[ -n "${email}" ]] ; then
6366
echo "Skipping notification for invalid address \"${email}\""
6467
fi
@@ -67,6 +70,22 @@ main() {
6770
return 0
6871
}
6972

73+
can_send() {
74+
if [[ -n "${PROFILE_NAME}" ]] ; then
75+
if [[ -n "${LIMIT_COMMAND_NAMES}" ]] ; then
76+
local IFS=",; "
77+
for cmd in ${LIMIT_COMMAND_NAMES} ; do
78+
[[ "${PROFILE_COMMAND}" == "$cmd" ]] && return 0
79+
done
80+
else
81+
return 0
82+
fi
83+
fi
84+
85+
[[ "${FORCE_SENDING}" == "1" ]]
86+
return $?
87+
}
88+
7089
send_mail() {
7190
${SEND_COMMAND} <<ERRMAIL
7291
To: $1

contrib/posix/README.md

+22-10
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
**Layout for `/etc/resticprofile`**:
44

5-
* `profiles.conf` - host centric default configuration
5+
* `conf.d/*` - default configuration and config overrides
6+
* `profiles.conf` - main configuration file
67
* `profiles.d/*` - host centric backup profiles (`*.toml` & `*.yaml`)
7-
* `conf.d/*` - overrides & extra configuration
8+
* `repositories.d/*` - restic repository configuration
9+
* `templates/*` - reusable config blocks and system templates
810

911
The layout is used in `deb`, `rpm` and `apk` packages of `resticprofile`
1012

1113
**Generated files**:
12-
* `conf.d/default-repository.secret` - during installation, only if missing
14+
* `repositories.d/default-repository.secret` - during installation, only if missing
1315

1416
**Referenced files and paths**:
15-
* `conf.d/default-repository-self-signed-pub.pem` - TLS public cert (self-signed only)
16-
* `conf.d/default-repository-client.pem` - TLS client cert
17+
* `repositories.d/default-repository-self-signed-pub.pem` - TLS public cert (self-signed only)
18+
* `repositories.d/default-repository-client.pem` - TLS client cert
1719
* `/var/lib/prometheus/node-exporter/resticprofile-*.prom` - Prometheus files
1820
* `$TMPDIR/resticprofile-*` - Status and lock files
1921

@@ -28,13 +30,23 @@ The layout is used in `deb`, `rpm` and `apk` packages of `resticprofile`
2830
Setup repository and validate system backup profile:
2931
```shell
3032
cd /etc/resticprofile/
31-
vim conf.d/repository.conf
33+
vim repositories.d/default.conf
3234
vim profiles.d/system.toml
3335
```
3436

35-
## Test config and backup
37+
## Verify configuration, backup & restore
3638
```shell
37-
resticprofile -n root show
38-
resticprofile -n root --dry-run backup
39-
resticprofile -n root backup
39+
resticprofile root.show
40+
resticprofile --dry-run root.backup
41+
resticprofile root.backup
42+
resticprofile root.snapshots
43+
resticprofile root.mount /mnt/restore &
44+
```
45+
46+
## Maintenance (check & prune)
47+
```shell
48+
resticprofile maintenance.check
49+
resticprofile maintenance.prune
50+
resticprofile maintenance.schedule
51+
resticprofile maintenance.unschedule
4052
```

contrib/posix/conf.d/backup.conf

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# -----------------------------------------------------------------------------
2+
##
3+
# Default configuration for backup & restore related commands
4+
#
5+
# This file should contain useful defaults to reduce amount of configuration
6+
# work needed in derived profiles. It should NOT contain a full backup config
7+
# having "source" definitions, since these whould be inherited by all backup
8+
# profiles that derive from "base" (or "default") settings.
9+
#
10+
# To define backup sources, create a profile config in "profiles.d" like:
11+
#
12+
# >>> "profiles.d/example.conf"
13+
#
14+
# [profiles.example]
15+
# description = "Backup example"
16+
# inherit = "base"
17+
#
18+
# [profiles.example.backup]
19+
# schedule = "daily"
20+
# source = [
21+
# "/path/to/backup",
22+
# "/other/path/to/backup",
23+
# ]
24+
#
25+
# <<<
26+
#
27+
28+
29+
##
30+
# Backup defaults
31+
[profiles.default.backup]
32+
33+
# Hostname and tags to identify backup snapshots in the repository
34+
{{ template "conf:default-host" . }}
35+
{{ template "conf:default-tags" . }}
36+
37+
# Exclude known cache files & folders from backups
38+
exclude-caches = true
39+
40+
# Exclude nested filesystems
41+
# Prefer overriding this option in dedicated backup profiles instead of
42+
# globally as it can greatly increase the volume if nested FS mounts are
43+
# contained in backup source paths.
44+
one-file-system = true
45+
46+
# Toggle whether a failure in reading a backup source is considered an error
47+
no-error-on-warning = false
48+
49+
# Wait on acquiring locks when running the profile on a schedule
50+
schedule-lock-wait = "45m"
51+
52+
# Specify the user that runs profile tasks on a schedule
53+
# "system" - root runs the profile tasks
54+
# "user" - user that created the schedule runs the profile tasks
55+
schedule-permission = "system"
56+
57+
# Toggle verbose output for troubleshooting
58+
#verbose = false
59+
60+
# Toggles immediate repository check before and after backup.
61+
# Checks can be heavy on resources. Consider scheduling "maintenance"
62+
# (see "conf.d/check.conf") instead of enabling checks here.
63+
check-before = false
64+
check-after = false
65+
66+
67+
##
68+
# Snapshot retention defaults
69+
[profiles.default.retention]
70+
# Remove obsolete snapshots prior to starting a backup
71+
before-backup = false
72+
# Remove obsolete snapshots after a successful backup
73+
after-backup = true
74+
75+
#
76+
# Note: Retention operates on host, path and tag filters to identify snapshots
77+
# to retain or remove. In most cases these filters should be in sync with
78+
# the backup configuration of a profile so that snapshots will be removed
79+
# that truely belong to a profile's backup.
80+
#
81+
82+
# Copying "host" block to identify snapshots by hostname
83+
{{ template "conf:default-host" . }}
84+
85+
# Retention allows to build tag filter from backup with 'true'. It is strongly
86+
# advised not to change this as tags are the primary filter besides hostname.
87+
tag = true
88+
89+
# Copying backup source paths to identify snapshots to retain or remove.
90+
# Set to "false" or a list of paths to disable or customize the path filter.
91+
#
92+
# It may make sense to disable path filters when source paths change. Ensure
93+
# that tags and hostname can properly identify snapshots when disabling paths.
94+
path = true
95+
96+
# Specify the snapshots to keep when checking for obsolete snapshots
97+
# Snapshots that do not match any condition are removed
98+
keep-tag = [ "forever" ]
99+
keep-last = 3
100+
#keep-hourly = 1
101+
#keep-daily = 1
102+
#keep-weekly = 1
103+
#keep-monthly = 1
104+
#keep-yearly = 1
105+
#keep-within = "30d"
106+
107+
# Use compact format for listing snapshots
108+
#compact = false
109+
110+
# Toggles immediate prune of the repository as snapshots are removed.
111+
#
112+
# While removing snapshots is a light operation, prune (reclaim space) can
113+
# be heavy on resources as it rewrites parts of the repository.
114+
# Consider scheduling "maintenance" (see "conf.d/prune.conf") instead of
115+
# enabling prune here.
116+
#
117+
# Also an attempt to recover a removed snapshot with "resticprofile recover"
118+
# only works as long as the repository was not yet pruned.
119+
prune = false
120+
121+
122+
##
123+
# Defaults for operations on repository snapshots of this host
124+
# Usage:
125+
# - "resticprofile snapshots" - view snapshots
126+
# - "resticprofile mount /mnt/restore" - mount snapshots
127+
# - "resticprofile ls latest /" - list files in a snapshot
128+
# - "resticprofile dump latest /file" - dump a file to stdout
129+
# - "resticprofile find PATTERN..." - find files in snapshots
130+
# - "resticprofile copy --repo2=..." - copy snapshots to repo2
131+
# - "resticprofile restore --target=/to/dir --include=PATTERN... latest"
132+
[profiles.default.copy]
133+
{{ template "conf:default-host" . }}
134+
schedule-lock-wait = "1h30m"
135+
[profiles.default.dump]
136+
{{ template "conf:default-host" . }}
137+
[profiles.default.find]
138+
{{ template "conf:default-host" . }}
139+
[profiles.default.forget]
140+
{{ template "conf:default-host" . }}
141+
[profiles.default.ls]
142+
{{ template "conf:default-host" . }}
143+
[profiles.default.mount]
144+
{{ template "conf:default-host" . }}
145+
[profiles.default.restore]
146+
{{ template "conf:default-host" . }}
147+
[profiles.default.snapshots]
148+
{{ template "conf:default-host" . }}
149+
[profiles.default.stats]
150+
{{ template "conf:default-host" . }}
151+
[profiles.default.tag]
152+
{{ template "conf:default-host" . }}
153+
154+
155+
##
156+
# Setup operations on repository snapshots for profiles deriving from "base"
157+
# Usage:
158+
# - "resticprofile profileName.snapshots" - view snapshots
159+
# - "resticprofile profileName.mount /mnt/restore" - mount snapshots
160+
# - "resticprofile profileName.ls latest /" - list files in a snapshot
161+
# - "resticprofile profileName.dump latest /file" - dump a file to stdout
162+
# - "resticprofile profileName.find PATTERN..." - find files in snapshots
163+
# - "resticprofile profileName.copy --repo2=..." - copy snapshots to repo2
164+
# - "resticprofile profileName.restore --target=/to/dir latest"
165+
[profiles.base.copy]
166+
{{ template "conf:default-tags" . }}
167+
[profiles.base.dump]
168+
{{ template "conf:default-tags" . }}
169+
[profiles.base.find]
170+
{{ template "conf:default-tags" . }}
171+
[profiles.base.forget]
172+
{{ template "conf:default-tags" . }}
173+
[profiles.base.ls]
174+
{{ template "conf:default-tags" . }}
175+
[profiles.base.mount]
176+
{{ template "conf:default-tags" . }}
177+
[profiles.base.restore]
178+
{{ template "conf:default-tags" . }}
179+
[profiles.base.snapshots]
180+
{{ template "conf:default-tags" . }}
181+
[profiles.base.stats]
182+
{{ template "conf:default-tags" . }}
183+
[profiles.base.tag]
184+
{{ template "conf:default-tags" . }}
185+
186+
187+
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)