How I can create an script to backup my postgres databases on linux systems using pg_dump
Already use the comand but i want someting execute itself no user interaction so
pg_dump -U postgres -W -Fc This ask for password and if I use -w ask for a pgpass file
1 Answer
It's an script for root user, place on /root directory:
#! /bin/sh USER="postgres" PASS="password" ## Staorage Dir bkp_dir="/home/USER_HOME/databases-$(date +%Y%m%d)" echo "Creating directory: ${bkp_dir}" mkdir $bkp_dir ## Temporal credential access file credentialsFile=".pgpass" echo "*:*:*:$USER:$PASS" >> $credentialsFile chmod 600 $credentialsFile echo "Backing up databases" pg_dump -U postgres -w -Fc > $bkp_dir/ rm $credentialsFile You can create a crontab for autorun the script as your wish
1