How to back up PostgreSQL databases using cronjobs?

Log in to your Hostginger hosting account.

Create a file named .pgbackup in the /home/username directory, where 'username' represents your Hostginger hosting account username.

Copy and paste the following text into the .pgbackup file. Replace 'dbname' with the name of the database you want to back up, 'dbusername' with a user who has access to the database, and 'password' with the database user's password:

#hostname:port:database:username:password
localhost:5432:dbname:dbusername:password

Save the changes to the .pgbackup file.

At the command prompt type:
chmod 600 .pgbackup

Create a cronjob that runs the following command. Replace 'dbusername' with the user who has access to the database, replace 'dbname' with the name of the database you want to back up, and replace 'path' with the path where you want to store the database backup file. This example uses backup.pg for the backup's filename, but you can use any filename you want:
/usr/bin/pg_dump --no-password -U dbusername dbname > /path/backup.pg
 

 

Was this answer helpful?

Related Articles

How to connect PostgreSQL using psql?

Log in to your Hostginger hosting account. Replace 'dbname' with the name of the database, and...

How to connect to PostgreSQL using PHP native functions?

Use the PHP code to connect to PostgreSQL and select a database. Replace 'username' with your...

How to connect to PostgreSQL using PDO (PHP Data Objects)?

PHP Data focus upon abstract database access, and enables you to use code that can handle...

How to connect to PostgreSQL using Python psycopg2 package?

To access PostgreSQL databases using Python, you must install psycopg2 package in a virtual...

How to connect to PostgreSQL using Python PyGreSQL?

To access PostgreSQL databases using Python, you must install PyGreSQL package in a virtual...