mirror of
https://github.com/phfroidmont/self-hosting.git
synced 2025-12-25 05:36:59 +01:00
Add backup config and fix timezone in containers
This commit is contained in:
parent
9f7679c7aa
commit
fe296230a8
15 changed files with 73 additions and 13 deletions
7
roles/daily-backup/files/daily-backup.service
Normal file
7
roles/daily-backup/files/daily-backup.service
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[Unit]
|
||||
Description=Full server backup
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/root/fullBackup.sh
|
||||
|
||||
10
roles/daily-backup/files/daily-backup.timer
Normal file
10
roles/daily-backup/files/daily-backup.timer
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Timer for daily backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 04:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
|
||||
23
roles/daily-backup/tasks/main.yml
Normal file
23
roles/daily-backup/tasks/main.yml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
- name: Create fullBackup.sh
|
||||
template:
|
||||
src: fullBackup.sh
|
||||
dest: /root/fullBackup.sh
|
||||
mode: 0700
|
||||
- name: Copy daily-backup.service
|
||||
copy:
|
||||
src: daily-backup.service
|
||||
dest: /etc/systemd/system/
|
||||
mode: 0700
|
||||
- name: Copy daily-backup.timer
|
||||
copy:
|
||||
src: daily-backup.timer
|
||||
dest: /etc/systemd/system/
|
||||
mode: 0700
|
||||
- name: Enable and start daily-backup
|
||||
systemd:
|
||||
name: daily-backup.timer
|
||||
state: started
|
||||
enabled: yes
|
||||
daemon_reload: yes
|
||||
|
||||
58
roles/daily-backup/templates/fullBackup.sh
Executable file
58
roles/daily-backup/templates/fullBackup.sh
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
REPOSITORY=ssh://backup@phf.ddns.net:2222/./backup
|
||||
|
||||
export BORG_PASSPHRASE='{{backup_borg_passphrase}}'
|
||||
|
||||
echo 'Dumping NextCloud database'
|
||||
docker exec nextcloud_db_1 sh -c "mysqldump -u nextcloud -p{{nextcloud_mysql_password}} nextcloud > /backups/database.dmp"
|
||||
|
||||
echo 'Dumping matrix database'
|
||||
docker exec matrix_db_1 sh -c "pg_dump -U synapse synapse > /backups/database.dmp"
|
||||
|
||||
echo 'Copying murmur database'
|
||||
docker stop murmur_murmur_1
|
||||
cp /var/lib/murmur/murmur.sqlite /backups/murmur/murmur.sqlite
|
||||
docker start murmur_murmur_1
|
||||
|
||||
echo 'Creating GitLab backup'
|
||||
docker exec gitlab_gitlab_1 gitlab-rake gitlab:backup:create
|
||||
|
||||
echo 'Starting Borg backup'
|
||||
borg create -v --stats --compression lz4 \
|
||||
${REPOSITORY}::'{hostname}-{now:%Y-%m-%d}' \
|
||||
/root \
|
||||
/home \
|
||||
/media \
|
||||
/etc \
|
||||
/var/lib/deluge \
|
||||
/var/lib/mailu \
|
||||
/var/lib/matrix/media_store \
|
||||
/var/lib/nextcloud \
|
||||
/var/lib/wiki \
|
||||
/backups \
|
||||
--exclude '/var/lib/nextcloud/db'
|
||||
|
||||
# Route the normal process logging to journalctl
|
||||
2>&1
|
||||
|
||||
# If there is an error backing up, reset password envvar and exit
|
||||
if [ "$?" = "1" ] ; then
|
||||
export BORG_PASSPHRASE=""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use the `prune` subcommand to maintain 14 daily, 8 weekly and 12 monthly
|
||||
# archives of THIS machine. The '{hostname}-' prefix is very important to
|
||||
# limit prune's operation to this machine's archives and not apply to
|
||||
# other machine's archives also.
|
||||
borg prune -v --list ${REPOSITORY} --prefix '{hostname}-' \
|
||||
--keep-daily=14 --keep-weekly=8 --keep-monthly=12
|
||||
|
||||
# Unset the password
|
||||
export BORG_PASSPHRASE=""
|
||||
|
||||
touch /backups/backup-ok
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue