ToolBox/borg-postgresql-backup.sh

18 lines
526 B
Bash

#!/bin/sh
# Borg repo location
REPOSITORY=/var/backup/database.borg/
# Example of remote repo
# REPOSITORY=ssh://backuper@192.168.1.100/var/backup/database.borg/
# Dump all postgres databases to file
sudo -u postgres pg_dumpall > /tmp/posgresql.sql
# Backup the sql file
borg create -v --stats --compression zlib,6 $REPOSITORY::$(date +%Y-%m-%d-%H:%M) /tmp/posgresql.sql
rm /tmp/posgresql.sql
# Delete old backups
borg prune -v $REPOSITORY --keep-daily=3 --keep-weekly=2 --keep-monthly=12
echo "`date +[%F/%T]` Done!"
exit