Databases

How can I setup automatic backups for my app?

Take a look at: https://hatchbox.gitbook.io/hatchbox/apps/backups

Where do I find my database credentials?

If you open your App in Hatchbox, click on Resources -> Database and all the details for connecting to your database will be listed there.

How can I manually backup my app database?

Backing up your database manually is pretty easy but takes a couple steps.

To find your Database

First, SSH into your server. Then we'll run pg_dump to dump our database. This will make a compressed dump of our database so it's smaller and easier to manage.

pg_dump -Fc database_name -U username -h localhost > database.bak

You'll now have a file called database.bak that you can download from the server.

On your local machine, you can use the following command to download the file from the remote server to the current directory your local machine.

scp deploy@IPADDRESS:~/database.bak .

How can I restore a backup of my database?

Similar to the above, but in reverse order

First, you'll copy your database up to the server using:

scp database.bak deploy@IPADDRESS:~

Then SSH into the server and run one of the following commands:

If your database already exists, you can run this command to restore to it:

pg_restore -U username -W -h 127.0.0.01 -d appname --no-acl --no-owner database.bak

If your database does not exist, you can run this command to create the database and restore it:

pg_restore -C -U username -W -h 127.0.0.01 -d appname --no-acl --no-owner database.bak

Last updated