You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to take backup PosgreSQL using pg_dump with crontab in Linux?
Find the pg_hba.conf file
sudo su - postgres
psql
SHOW hba_file;
Change the method to 'trust' and save the file
sudo vim /etc/postgresql/11/main/pg_hba.conf
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
Restart the PostgreSQL service after the above changes
sudo systemctl restart postgresql
Make shell script to take the backup. I gave the filename as /data/postgresql-backup.sh.
sudo crontab -e
# Add below content in the crontab. It will take the backup for every 3-hours
# PostgreSQL backup
0 */3 * * * /data/postgresql-backup.sh
Thanks