Page MenuHomeSoftware Heritage
Paste P1269

quick and dirty postgresql backup script based on zfs snapshot
ActivePublic

Authored by vsellier on Jan 27 2022, 10:25 AM.
root@dali:~# cat backup.sh
#!/bin/bash
i=0
dataset=data/postgresql
wal=data/postgresql/wal
while true; do
id=$(printf "%03d%s\n" $i)
echo Switch pg in backup mode
sudo -i -u postgres psql -c "select pg_start_backup('$id')"
echo Creating postgresql snapshot
zfs snapshot ${dataset}@$id
echo Removing backup mode
sudo -i -u postgres psql -c "select pg_stop_backup()"
echo Creating wal snapshot
zfs snapshot ${wal}@$id
echo Sleep
i=$(( $i + 1 ))
sleep 15
done