Scheduled PostgreSQL backups using pgAdmin and pgAgent

Published: 22 June 2023
on channel: DnoCode
2,555
21

Install pgAgent:
sudo apt install pgagent

In pgAdmin add extension:
CREATE EXTENSION pgagent;

Create file .pgpass in your user folder with:
YourHost:YourPort:YourBase:YourUser:YourPassword
For example: *:5432:test_base:bak_user:123

Then restrict access to it:
chmod 600 .pgpass

Add your DataBase user to pg_hba.conf

Restart postgres service:
sudo service postgresql restart

Add pgAgent as a daemon on your server:
pgagent host=/var/run/postgresql dbname=test_base user=bak_user

For some reason, pgAgent Jobs is appeared only if you create a connection where the Maintenance database is the database to be backed up. If you know how to fix this please let me know in the comments.

Code that would be executed on schedule:
pg_dump --username=bak_user --dbname=test_base --clean --file=/home/user/backup-`date +%d-%m-%Y-%H-%M-%S`.sql


midnight commander (not necessary) :
sudo apt install mc


On this page of the site you can watch the video online Scheduled PostgreSQL backups using pgAdmin and pgAgent with a duration of hours minute second in good quality, which was uploaded by the user DnoCode 22 June 2023, share the link with friends and acquaintances, this video has already been watched 2,555 times on youtube and it was liked by 21 viewers. Enjoy your viewing!