Repository navigation
|
Hello everyone, I'm confronted with the following problem: after migrating my Nextcloud instance to a new server using resticprofile I want to achieve basically this:
Problem: My current profiles.yaml (redacted) for reference: ---
version: '1'
global:
initialize: true
default:
repository: rest:https://backup.example.com/home
password-file: password.txt
env:
RESTIC_REST_USERNAME: home
RESTIC_REST_PASSWORD: *****
backup:
schedule-after-network-online: true
schedule-lock-wait: 1h
retention:
before-backup: false
after-backup: true
host: true
keep-daily: 7
keep-weekly: 4
keep-monthly: 12
path: true
prune: true
tag: true
adm:
inherit: default
backup:
exclude-caches: true
exclude:
- /srv/data/firefly/db
- /srv/data/influxdb
- /srv/data/nextcloud/db
- /var/lib/apt
source:
- /etc
- /srv/cloud/data
- /srv/data
- /var/backups
- /var/lib
- /var/spool
schedule: 02:00
tag:
- adm
retention:
keep-daily: 14
keep-weekly: 9
keep-monthly: 24
nextcloud-mariadb:
inherit: default
backup:
run-before: docker exec --user www-data nextcloud php occ maintenance:mode --on
run-after: docker exec --user www-data nextcloud php occ maintenance:mode --off
stdin: true
stdin-command: docker exec nextcloud-mariadb mariadb-dump --single-transaction --default-character-set=utf8mb4 -u nextcloud -p***** nextcloud
stdin-filename: nextcloud-mariadb.sql
schedule: 03:00
tag:
- stdin
- mariadb
- nextcloud |
Replies: 3 comments
|
You don't need two profiles. Dump the database to a file in nextcloud:
inherit: default
backup:
run-before:
- sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
- mysqldump --single-transaction --databases nextcloud > /var/backups/nc-db.sql
source:
- /var/www/nextcloud
- /var/nextcloud-data
- /var/backups/nc-db.sql
run-finally:
- rm -f /var/backups/nc-db.sql
- sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off
|
|
If you want to keep the streamed database backup as a separate profile, a group can run the two profiles in order, with one shell wrapper owning the maintenance window. This is an alternative to the temporary-dump approach above. For your existing version 1 config, add: groups:
nextcloud-consistent:
- adm
- nextcloud-mariadbMerge #!/usr/bin/env bash
set -euo pipefail
maintenance_started=0
cleanup() {
local rc=$?
trap - EXIT
if (( maintenance_started )); then
if ! docker exec --user www-data nextcloud php occ maintenance:mode --off; then
echo 'Failed to leave maintenance mode; manual recovery is needed.' >&2
rc=1
fi
fi
exit "$rc"
}
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM
docker exec --user www-data nextcloud php occ maintenance:mode --on
maintenance_started=1
resticprofile --name nextcloud-consistent backupRun this from the directory containing your profile config (or supply its path explicitly). It assumes Nextcloud was not already in maintenance mode for another operation. Schedule the wrapper as one job and remove/disable the two independent backup schedules for this workflow; also prevent overlapping wrapper runs. The group command syntax is supported, but the current group configuration doesn't expose group-wide before/finally hooks. The wrapper supplies that boundary and attempts cleanup on ordinary failures and termination signals. It cannot recover from SIGKILL or a host crash, so maintenance mode still needs checking after those. One tradeoff: your |
|
Thanks for your suggestions, I more or less combined them for what I'm doing now. Let me show you and describe: nextcloud:
inherit: default
backup:
run-before:
- docker exec --user www-data nextcloud php occ maintenance:mode --on
- docker exec nextcloud-mariadb mariadb-dump --single-transaction --default-character-set=utf8mb4 -u nextcloud -p***** nextcloud > '/srv/data/nextcloud/backup/nextcloud-mariadb.sql'
exclude:
- /srv/data/nextcloud/db
source:
- /srv/data/nextcloud
- /srv/cloud/data
run-finally:
- rm -rv '/srv/data/nextcloud/backup/nextcloud-mariadb.sql'
- docker exec --user www-data nextcloud php occ maintenance:mode --off
schedule: 03:00
tag:
- nextcloud
Did not want to maintain another script outside from resticprofile. |
Thanks for your suggestions, I more or less combined them for what I'm doing now. Let me show you and describe: