diff --git a/examples/example.borg b/examples/example.borg index 4fced667058a0345e138dd297fa3dacd86d5c8ea..9544a9407c95bf3c0df23a074c3875a5e162cbbd 100644 --- a/examples/example.borg +++ b/examples/example.borg @@ -46,6 +46,22 @@ ## Default: # bwlimit = 0 +## export "borg info last_archive" to a given file +## this is usefull for monitoring without using borg +## +## Example: +# borginfo = /var/backups/borginfo.json +## Default: +# borginfo = + +## export "borg list repository" to a given file +## this is usefull for monitoring without using borg +## +## Example +# borglist = /var/backups/borglist.json +## Default: +# borglist = + ###################################################### ## source section ## (where the files to be backed up are coming from) diff --git a/handlers/borg.in b/handlers/borg.in index fa309c79ca7d0ce889a97236142e8fa796cbde48..0fc72b622844184f92061a328ca5900cbe30ad2e 100644 --- a/handlers/borg.in +++ b/handlers/borg.in @@ -31,6 +31,9 @@ getconf nicelevel 0 getconf ionicelevel getconf bwlimit +getconf borginfo +getconf borglist + setsection source getconf init yes getconf include @@ -250,8 +253,48 @@ if [ "$prune" == "yes" ]; then warning "$output" warning "Removing old backups finished with warnings." else - error $output - fatal "Failed removing old backups." + info "$output" + warning "Failed removing old backups. Borg returned exit code ${ret}." + fi + fi +fi + +### WRITE STATS FILES ### + +if [ -n "$borginfo" ]; then + mkdir -p "$(dirname "$borginfo")" + + infostr="borg info $execstr_repository --last 1 --json > $borginfo" + + debug "$infostr" + if [ "$test" = 0 ]; then + output=$(su -c "$infostr" 2>&1) + ret=$? + if [ $ret = 0 ]; then + debug "$output" + info "Successfully writing borg info to $borginfo" + else + info "$output" + error "Failed to write borg info to $borginfo" + fi + fi +fi + +if [ -n "$borglist" ]; then + mkdir -p "$(dirname "$borglist")" + + infostr="borg list $execstr_repository --json > $borglist" + + debug "$infostr" + if [ "$test" = 0 ]; then + output=$(su -c "$infostr" 2>&1) + ret=$? + if [ $ret = 0 ]; then + debug "$output" + info "Successfully writing borg list to $borglist" + else + info "$output" + error "Failed to write borg list to $borglist" fi fi fi