Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic backup of PostgreSQL database in Ubuntu

How to take an automatic backup of a PostgreSQL database in Ubuntu? Or is there a script available to take time-to-time PostgreSQL database backups?

like image 424
mahendra kamble Avatar asked Jun 08 '16 13:06

mahendra kamble


People also ask

How do I backup a PostgreSQL database?

Backing up a PostgreSQL Database To back up your database onto a plain-text SQL file, simply login to your database server. Then switch to the Postgres account, and run the command. The plain-text SQL file will have the commands required to reconstruct the entire database to its state when backed up.

How do you backup and restore PostgreSQL database on Linux?

To back up, a PostgreSQL database, start by logging into your database server, then switch to the Postgres user account, and run pg_dump as follows (replace tecmintdb with the name of the database you want to backup). By default, the output format is a plain-text SQL script file.

Where is Postgres data stored Ubuntu?

PostgreSQL configuration files are stored in the /etc/postgresql/<version>/main directory. For example, if you install PostgreSQL 12, the configuration files are stored in the /etc/postgresql/12/main directory.


1 Answers

you can use the following:

sudo crontab -e

at the end of the file add this:

0 6 * * * sudo pg_dump -U USERNAME -h REMOTE_HOST -p REMOTE_PORT NAME_OF_DB > LOCATION_AND_NAME_OF_BACKUP_FILE

This command will take an automated backup of your selected db everyday at 6:00 AM (after changing options of the command to fit to ur db)

like image 97
Ghassan Zein Avatar answered Oct 06 '22 17:10

Ghassan Zein