Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dobrivoje/e1be29c50867aee91ff1f2e8393d56c5 to your computer and use it in GitHub Desktop.
Save dobrivoje/e1be29c50867aee91ff1f2e8393d56c5 to your computer and use it in GitHub Desktop.
pg_backup_single_cpu.sh
#!/bin/bash
BACKUP_DIR="/backup-nas/backup-db/"
PGHOST="localhost"
PGUSER="postgres"
PGPASSWORD="<enter password here>"
SERVER_IP_ADDRESS=10.100.129.212
BACKUP_LOCATION=/HosDB/backup/on2hour
DATABASE_NAME=retailconnect
export PGPASSWORD
time=`date '+%d'-'%m'`
echo "============================================================================================="
echo "Start backup on " `date '+%X'-'%T' `
echo "============================================================================================="
pg_dump rc-nis -h $SERVER_IP_ADDRESS -U postgres -f /tmp/$DATABASE_NAME-$time.back -i
PGPASSWORD=""
export PGPASSWORD
echo "============================================================================================="
echo "Backup finished. Compression started at : " `date '+%X'`
echo "============================================================================================="
gzip -c /tmp/$DATABASE_NAME-$time.back > $BACKUP_LOCATION/$DATABASE_NAME-$time.gz
rm -f /tmp/$DATABASE_NAME-$time.back
rem Find the latest backup file, in case we already have more of them..
find $BACKUP_LOCATION/ -mtime +1 -exec rm {} \;
echo "============================================================================================="
echo "Backup finished at : " `date '+%X'`
echo "============================================================================================="
@dobrivoje
Copy link
Author

The simplest way to backup PostgresSQL database in single CPU mode

PGPASSWORD="nis321"
export PGPASSWORD
pg_dump rc-nis -h 10.100.129.212 -U postgres -f /tmp/database.backup.back -i
gzip -c /tmp/database.backup.back > /DBBackups/database.backup.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment