Databases

How can I setup automatic backups for my app?

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.
1
pg_dump -Fc database_name -U username -h localhost > database.bak
Copied!
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.
1
scp [email protected]:~/database.bak .
Copied!

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:
1
scp database.bak [email protected]:~
Copied!
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:
1
pg_restore -U username -W -h 127.0.0.01 -d appname --no-acl --no-owner database.bak
Copied!
If your database does not exist, you can run this command to create the database and restore it:
1
pg_restore -C -U username -W -h 127.0.0.01 -d appname --no-acl --no-owner database.bak
Copied!
Last modified 10mo ago