-
Notifications
You must be signed in to change notification settings - Fork 48
/
backup_nextcloud.sh.j2
37 lines (26 loc) · 1.35 KB
/
backup_nextcloud.sh.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
export RESTIC_REPOSITORY="{{ restic_repo }}"
export RESTIC_PASSWORD="{{ restic_backup_secret }}"
# abort entire script if any command fails
set -e
# unlock restic to keep automatic backups going
{{ restic_install_path }}/restic unlock --cleanup-cache
# Make sure nextcloud is enabled when we are done
trap "docker exec -u www-data nextcloud php occ maintenance:mode --off" EXIT
# set nextcloud to maintenance mode
docker exec -u www-data nextcloud php occ maintenance:mode --on
{% if nextcloud_db_type == 'mysql' %}
sudo docker exec nextcloud-db mysqldump --single-transaction -h localhost -u {{ nextcloud_db_user }} -p{{ nextcloud_db_passwd }} {{ nextcloud_db_name }} > {{ nextcloud_database_dump_dir }}/db_dump_{{ nextcloud_db_type }}_nextcloud.sql
{% elif nextcloud_db_type == 'pgsql' %}
sudo docker exec nextcloud-db pg_dump -c -U {{ nextcloud_db_user }} {{ nextcloud_db_name }} > {{ nextcloud_database_dump_dir }}/db_dump_{{ nextcloud_db_type }}_nextcloud.sql
{% endif %}
# backup the data dir
{{ restic_install_path }}/restic backup --verbose {{ nextcloud_base_dir }}
#
# end maintenance mode
docker exec -u www-data nextcloud php occ maintenance:mode --off
# delete trap
trap "" EXIT
# clean up backup dir
{{ restic_install_path }}/restic forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75
{{ restic_install_path }}/restic prune