Skip to content

Commit fb7c14d

Browse files
committed
Run backup create with set +e if pruning is enabled
In case a file changes during a backup, borg will log a warning like this: ``` Nov 07 18:30:05 webserver01 borg-backup[849693]: Creating archive at "backup:webserver01::backup-20231107-183001" Nov 07 18:30:42 webserver01 borg-backup[849693]: /var/lib/postgresql/16/main/pg_wal/00000001000000010000004E: file changed while we backed it up Nov 07 18:30:59 webserver01 borg-backup[849693]: /var/lib/fail2ban/fail2ban.sqlite3: file changed while we backed it up ``` It will finish the backup, but the exit code will be 1. Because of the set -e at the top, the script will exit. If manage_prune is true, a prune command is configured. It won't be executed when a file change during a backup. We now add `|| true` to the backup create command.
1 parent 1e1904b commit fb7c14d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

spec/classes/init_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
it { is_expected.to contain_file('/etc/borg') }
2626
it { is_expected.to contain_file('/etc/profile.d/borg.sh') }
27-
it { is_expected.to contain_file('/usr/local/bin/borg-backup') }
27+
it { is_expected.to contain_file('/usr/local/bin/borg-backup').with_content(%r{borg create.*" \|\| true}) }
2828
it { is_expected.to contain_file('/usr/local/bin/borg_exporter') }
2929
it { is_expected.to contain_file('/etc/borg-restore.cfg') }
3030
it { is_expected.to contain_class('borg::install') }
@@ -190,7 +190,7 @@
190190
}
191191
end
192192

193-
it { is_expected.not_to contain_file('/usr/local/bin/borg-backup').with_content(%r{/^\s+borg prune/}) }
193+
it { is_expected.to contain_file('/usr/local/bin/borg-backup').without_content(%r{/^\s+borg prune/}).without_content(%r{borg create.*" \|\| true}) }
194194
end
195195

196196
context 'with absolute backup destination dir present' do

templates/borg-backup.sh.epp

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ backup_borg() {
180180
# Change the working directory in case the source paths are relative
181181
cd "<%= $working_directory %>"
182182

183-
borg create "${options[@]}" --stats --verbose "$dst::backup-$(date "+%Y%m%d-%H%M%S")" "${src[@]}"
183+
borg create "${options[@]}" --stats --verbose "$dst::backup-$(date "+%Y%m%d-%H%M%S")" "${src[@]}"<% if $manage_prune { %> || true<% } %>
184184
<% if $manage_prune { -%>
185185
# keep all backups from the last <%= $keep_within %> days
186186
# keep at least one backup for each day for <%= $keep_daily %> days

0 commit comments

Comments
 (0)