script to take the dump backup in postgresql
Create directory : /home/postgres/BACKUP
create below folders inside BACKUP
BASEBACKUPS
DUMPS
scripts
inside dumps create logs , PGDUMP folders.
inside scripts put the below script with name you like and give execution permissions. I gave name dump_backup.sh
chmod +x dump_backup.sh
#!/bin/bash
LOG_LOC=/home/postgres/BACKUP/DUMPS/logs
BACKUP_LOC=/home/postgres/BACKUP/DUMPS/PGDUMP
DATABASE=$1
DUMP_FILE=$BACKUP_LOC”/”$DATABASE”_”$(date +%d%m%Y%H%M).custom
LOG_FILE=$LOG_LOC”/”$DATABASE”_”$(date +%d%m%Y%H%M).log
pg_dump –file=$DUMP_FILE –format=c –verbose –blobs –create $DATABASE >> $LOG_FILE 2>&1
if [ $? -eq 0 ]
then
echo “Backup is successful” >> $LOG_FILE
else
echo “Backup failed” >> $LOG_FILE
fi
Execute script using below command:
sh dump_backup.sh postgres ==> This will take the dump of postgres database in custom format.