Andre Spadini
André Spadini | MultiCloud | DBA

André Spadini | MultiCloud | DBA

PostgreSQL: Script de Backup

PostgreSQL: Script de Backup

Andre Spadini's photo
Andre Spadini

Published on Nov 2, 2021

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Segue abaixo script de bakcup para backup de todas as databases do PostgreSQL.

# Location to place backups.
#String to append to the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days you want to keep copie of your databases
databases=`/usr/bin/psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do
  if [ "$i" != "template0" ] && [ "$i" != "template1" ]; then
    echo Dumping $i to $backup_dir$i\_$backup_date
   /usr/bin/pg_dump  -Fc $i > $backup_dir$i\_$backup_date.dump
find $backup_dir -type f -prune -mtime +$number_of_days -exec rm -f {} \;
Share this