vps/synapse/backup.sh
2023-11-29 13:50:53 +00:00

24 lines
802 B
Bash
Executable file

#!/bin/bash
if [[ $UID -ne 0 ]]; then
echo "Must be run as root."
exit 1
fi
media_dir="/mnt/synapsedata/media_store"
backup_date="$(date '+%Y%m%d-%Hh%Mm')"
bak_folder="/mnt/backups/synapsebackup"
borg_repo="$bak_folder/borg"
mkdir -p "$bak_folder"
# PSQL
echo "Creating backup of PosgreSQL databases to $bak_folder/dump_$backup_date.sql"
docker exec -t synapse_postgres pg_dumpall -c -U synapse > "$bak_folder/dump_$backup_date.sql"
echo "Done, total size of all backups: $(du -hc $bak_folder/dump_* | grep total | grep -oP '^[\d\w]+')."
# Media
[[ -d "$borg_repo" ]] || borg init --encryption=none "$borg_repo"
borg create --stats "$borg_repo::media-{now:%Y-%m-%d_%H:%M:%S}" "$media_dir"
borg prune --stats --keep-daily=7 --keep-weekly=4 --keep-monthly=3 "$borg_repo"
borg compact "$borg_repo"