Posted: Wed Dec 13, 2023 10:13 am Post subject: postgresql schedule backup
To perform a backup with this utility, just call it and specify the destination file:
su - postgres
pg_dump -U postgres db_name | gzip > backup_file.gz
You can add a cron job to run backups regularly. To this end, follow the steps below:
Create a backup storage folder
sudo mkdir -p /backups/postgresql
Provide the postgres user permissions to the directory
sudo chown postgres /backups/postgresql
Set the PostgreSQL user
su - postgres
Open crontab by running the command
crontab -e
Add this line at the end, replacing db_name with the name of your database
0 0 * * 0 pg_dump -U postgres db_name | gzip > /backups/postgresql/db_name\_`date +20\%y\%m\%d`.gz.gz
This way, a backup will be performed on your server at midnight on Saturday. This is the most basic solution to a backup task.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum