add backup scripts and systemd units

This commit is contained in:
Daniel Micay 2022-07-22 00:40:20 -04:00
parent 989ed9718c
commit 7054e7c09f
4 changed files with 44 additions and 0 deletions

15
local-backup Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
remote=root@matrix.grapheneos.org
timestamp=$(date -u +%Y-%m-%dT%H:%m:%SZ)
ssh $remote "rm -rf local-backup"
ssh $remote "mkdir local-backup"
ssh $remote "mkdir local-backup/$timestamp"
ssh $remote "pg_dumpall -U postgres > local-backup/$timestamp/all_databases.sql"
ssh $remote "cp -a /etc/synapse local-backup/$timestamp/synapse"
ssh $remote "tar c -C local-backup $timestamp | zstd -9 | age -r \$(cat backup-public-key.txt) -o local-backup/$timestamp.tar.zst.age"
rsync -v $remote:./local-backup/$timestamp.tar.zst.age backup/

13
remote-backup Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
timestamp=$(date -u +%Y-%m-%dT%H:%m:%SZ)
rm -rf remote-backup
mkdir remote-backup
mkdir remote-backup/$timestamp
pg_dumpall -U postgres > remote-backup/$timestamp/all_databases.sql
cp -a /etc/synapse remote-backup/$timestamp/synapse
tar c remote-backup/$timestamp | zstd -9 | age -r $(cat backup-public-key.txt) -o remote-backup/$timestamp.tar.zst.age
sshpass -f cloud-archive-password.txt rsync -v ./remote-backup/$timestamp.tar.zst.age pca@gateways.storage.gra.cloud.ovh.net:backup/

8
remote-backup.service Normal file
View File

@ -0,0 +1,8 @@
[Unit]
Description=Perform remote backup
[Service]
ExecStart=/usr/local/bin/remote-backup
Type=oneshot
User=root
WorkingDirectory=/root

8
remote-backup.timer Normal file
View File

@ -0,0 +1,8 @@
[Unit]
Description=Perform remote backup backups daily
[Timer]
OnCalendar=daily
[Install]
WantedBy=timers.target