From a7c123cb7a917b580ed95e2184843d0377fc8613 Mon Sep 17 00:00:00 2001 From: Gitea Date: Thu, 24 Oct 2024 18:54:02 -0400 Subject: added postgres backup script from server --- psqlbak.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 psqlbak.sh diff --git a/psqlbak.sh b/psqlbak.sh new file mode 100755 index 0000000..513cfd6 --- /dev/null +++ b/psqlbak.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# +## Daily PostgreSQL maintenance: vacuuming and backuping. +# +### +set -e +for DB in $(psql -l -t -U postgres -hlocalhost |awk '{ print $1}' |grep -vE '^-|:|^List|^Name|template[0|1]|postgres|\|'); do + echo "[`date`] Maintaining $DB" + echo 'VACUUM' | psql -U postgres -hlocalhost -d $DB + DUMP="/home/lxf/bak/postgres/$DB.`date '+%Y%m%d'`.sql.gz" + pg_dump -U postgres -hlocalhost $DB | gzip -c > $DUMP + PREV="$DB.`date -d'1 day ago' '+%Y%m%d'`.sql.gz" + md5sum -b $DUMP > $DUMP.md5 + if [ -f $PREV.md5 ] && diff $PREV.md5 $DUMP.md5; then + rm $DUMP $DUMP.md5 + fi +done -- cgit v1.2.3-70-g09d2