Skip to content
Snippets Groups Projects
Commit e7d5a2cb authored by Julian's avatar Julian
Browse files

post_run and pre_run hook support

parent 231c9832
No related branches found
No related tags found
1 merge request!1post_run and pre_run hook support
......@@ -100,4 +100,12 @@ exclude_files: {}
# Only supportet in restic based backups
# Ignored in vm-via-hypervisor mode
include_files: {}
# Run one or more hooks before and after each (standalone) backup run
# Items are executed in bash in their own subshell
hooks:
pre_run:
- mysqldump --all-databases > /var/backups/mysql-backup.sql
post_run:
- rm /var/backups/mysql-backup.sql
```
......@@ -48,3 +48,6 @@ backups:
'/root/.ansible/*': true
include_files:
'/': true
hooks:
pre_run: []
post_run: []
......@@ -3,7 +3,17 @@ set -euo pipefail
test -f "/etc/backup-client/enabled" || { echo "Standalone backup is disabled"; exit 0; }
{% if backups.hooks.pre_run %}
echo "Running pre_run hooks"
{% for cmd in backups.hooks.pre_run %}
( {{ cmd }} )
{% endfor %}
echo "Hooks done"
{% endif %}
{% if backup_backend == 'restic' %}
# Run restic in subshell to avoid leaking environment to post_run hooks
(
# restic backend
source /etc/backup-client/restic.env
......@@ -15,9 +25,16 @@ restic backup \
--exclude "${RESTIC_REPOSITORY}" \
--exclude-file "/etc/backup-client/exclude_files" \
--files-from "/etc/backup-client/include_files"
)
{% endif %}
{% if not backup_backend %}
echo "Noop, backup is handled external"
{% endif %}
{% if backups.hooks.post_run %}
echo "Running post_run hooks"
{% for cmd in backups.hooks.post_run %}
( {{ cmd }} )
{% endfor %}
echo "Hooks done"
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment