Skip to content

Commit 4c69130

Browse files
committed
Updated to config v2
1 parent b46f27e commit 4c69130

21 files changed

+951
-359
lines changed

.goreleaser.yml

Lines changed: 13 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 22 additions & 3 deletions
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

Lines changed: 22 additions & 10 deletions
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

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
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 to identify backup snapshots in the repository from this host
34+
{{ template "conf:default-host" . }}
35+
36+
#
37+
# Tags (besides host & path) are used to identify snapshots belonging to
38+
# a certain backup.
39+
#
40+
# Multiple tags can be defined, but profile name should always be included,
41+
# the expression "{{ .Profile.Name }}" resolves to the currently active
42+
# profile name.
43+
#
44+
# Notes:
45+
#
46+
# - Set the same tags for "backup" and "retention" unless you know what you
47+
# are doing. Retention uses the tags defined in the backup section when
48+
# "tag = true" is set in the retention configuration and this default
49+
# setup should not be changed.
50+
#
51+
# - Most of the command sections should use "tag = true" to copy tags from
52+
# backup so that restore, mount, etc. relate to the selected profile.
53+
#
54+
tag = [ "{{ .Profile.Name }}" ]
55+
56+
# Exclude known cache files & folders from backups
57+
exclude-caches = true
58+
59+
# Exclude nested filesystems
60+
# Prefer overriding this option in dedicated backup profiles instead of
61+
# globally as it can greatly increase the volume if nested FS mounts are
62+
# contained in backup source paths.
63+
one-file-system = true
64+
65+
# Toggle whether a failure in reading a backup source is considered an error
66+
no-error-on-warning = false
67+
68+
# Wait on acquiring locks when running the profile on a schedule
69+
schedule-lock-wait = "45m"
70+
71+
# Specify the user that runs profile tasks on a schedule
72+
# "system" - root runs the profile tasks
73+
# "user" - user that created the schedule runs the profile tasks
74+
schedule-permission = "system"
75+
76+
# Toggle verbose output for troubleshooting
77+
#verbose = false
78+
79+
# Toggles immediate repository check before and after backup.
80+
# Checks can be heavy on resources. Consider scheduling "maintenance"
81+
# (see "conf.d/check.conf") instead of enabling checks here.
82+
check-before = false
83+
check-after = false
84+
85+
86+
##
87+
# Snapshot retention defaults
88+
[profiles.default.retention]
89+
# Remove obsolete snapshots prior to starting a backup
90+
before-backup = false
91+
# Remove obsolete snapshots after a successful backup
92+
after-backup = true
93+
94+
#
95+
# Note: Retention operates on host, path and tag filters to identify snapshots
96+
# to retain or remove. In most cases these filters should be in sync with
97+
# the backup configuration of a profile so that snapshots will be removed
98+
# that truely belong to a profile's backup.
99+
#
100+
101+
# Copying "host" block to identify snapshots by hostname
102+
{{ template "conf:default-host" . }}
103+
104+
# Retention allows to build tag filter from backup with 'true'. It is strongly
105+
# advised not to change this as tags are the primary filter besides hostname.
106+
tag = true
107+
108+
# Copying backup source paths to identify snapshots to retain or remove.
109+
# Set to "true" to copy source paths from backup, "false" or a list of paths
110+
# to disable or customize the path filter.
111+
#
112+
# Note: Path filter matches literally on absolute paths recorded as sources
113+
# when a snapshot was created. Tag and host filters are better suited to
114+
# identify snapshots of certain profile. Default is not to use path.
115+
path = false
116+
117+
# Specify the snapshots to keep when checking for obsolete snapshots
118+
# Snapshots that do not match any condition are removed
119+
keep-tag = [ "forever" ]
120+
keep-last = 3
121+
#keep-hourly = 1
122+
#keep-daily = 1
123+
#keep-weekly = 1
124+
#keep-monthly = 1
125+
#keep-yearly = 1
126+
#keep-within = "30d"
127+
128+
# Use compact format for listing snapshots
129+
#compact = false
130+
131+
# Toggles immediate prune of the repository as snapshots are removed.
132+
#
133+
# While removing snapshots is a light operation, prune (reclaim space) can
134+
# be heavy on resources as it rewrites parts of the repository.
135+
# Consider scheduling "maintenance" (see "conf.d/prune.conf") instead of
136+
# enabling prune here.
137+
#
138+
# Also an attempt to recover a removed snapshot with "resticprofile recover"
139+
# only works as long as the repository was not yet pruned.
140+
prune = false
141+
142+
143+
##
144+
# Defaults for operations on repository snapshots of this host
145+
# Usage:
146+
# - "resticprofile snapshots" - view snapshots
147+
# - "resticprofile mount /mnt/restore" - mount snapshots
148+
# - "resticprofile ls latest /" - list files in a snapshot
149+
# - "resticprofile dump latest /file" - dump a file to stdout
150+
# - "resticprofile find PATTERN..." - find files in snapshots
151+
# - "resticprofile copy --repo2=..." - copy snapshots to repo2
152+
# - "resticprofile restore --target=/to/dir --include=PATTERN... latest"
153+
[profiles.default.copy]
154+
{{ template "conf:default-host" . }}
155+
schedule-lock-wait = "1h30m"
156+
[profiles.default.dump]
157+
{{ template "conf:default-host" . }}
158+
[profiles.default.find]
159+
{{ template "conf:default-host" . }}
160+
[profiles.default.forget]
161+
{{ template "conf:default-host" . }}
162+
[profiles.default.ls]
163+
{{ template "conf:default-host" . }}
164+
[profiles.default.mount]
165+
{{ template "conf:default-host" . }}
166+
[profiles.default.restore]
167+
{{ template "conf:default-host" . }}
168+
[profiles.default.snapshots]
169+
{{ template "conf:default-host" . }}
170+
[profiles.default.stats]
171+
{{ template "conf:default-host" . }}
172+
[profiles.default.tag]
173+
{{ template "conf:default-host" . }}
174+
175+
176+
##
177+
# Setup operations on repository snapshots for profiles deriving from "base"
178+
# Usage:
179+
# - "resticprofile profileName.snapshots" - view snapshots
180+
# - "resticprofile profileName.mount /mnt/restore" - mount snapshots
181+
# - "resticprofile profileName.ls latest /" - list files in a snapshot
182+
# - "resticprofile profileName.dump latest /file" - dump a file to stdout
183+
# - "resticprofile profileName.find PATTERN..." - find files in snapshots
184+
# - "resticprofile profileName.copy --repo2=..." - copy snapshots to repo2
185+
# - "resticprofile profileName.restore --target=/to/dir latest"
186+
[profiles.base.copy]
187+
tag = true
188+
[profiles.base.dump]
189+
tag = true
190+
[profiles.base.find]
191+
tag = true
192+
[profiles.base.forget]
193+
tag = true
194+
[profiles.base.ls]
195+
tag = true
196+
[profiles.base.mount]
197+
tag = true
198+
[profiles.base.restore]
199+
tag = true
200+
[profiles.base.snapshots]
201+
tag = true
202+
[profiles.base.stats]
203+
tag = true
204+
[profiles.base.tag]
205+
tag = true
206+
207+
208+
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)