I have an app on Heroku, using PHP and PostgreSQL. Now I would like to create backup of my database regularly, put it on a folder on the server, or record its S3 urls and download it.
-
I have been doing research on the topic. It seems that the best is to use pgbackups add-on which I already have and can use on local command line, like:
heroku pgbackups:url --app=APP_NAME -
I want to automate the process, lets say in a cron job. I see we have workers on Heroku, but I have never used them and this is still a development environment. A free plan does not have workers. Besides, my app doesnt really require background workers. I dont want to buy worker dynos only for automatic database backups. Which way should I go?
-
If I can create PHP cron jobs on Heroku, then I need to know: How can I run Heroku commands in PHP? I tried exec and passthru, but none of them seems to work on Heroku server. On my localhost, the above command (
heroku pgbackups) works pretty well, providing the Heroku toolbelt installed on local server. -
For Ruby, they have https://github.com/heroku/ toolkit for server-side commands. But I had no luck in my search for a PHP branch…
The overall purpose is to have the DB backup and store it on the server and download it. (Even though Heroku makes backups itself, we want to see it in our hands 🙂
How can I make it happen?
Probably the best thing to do is to have a cron job on your backup server to run
heroku pgbackups:urland to get a URL to the latest pgbackup, and then download it withcurl. Something like this:For more info about
heroku pgbackups:url, see:https://devcenter.heroku.com/articles/pgbackups#downloading-a-backup
Doing anything with worker dynos wouldn’t really make sense because that wouldn’t really help you get the backup to your backup server unless you were downloading and re-uploading it or something. Just running a cron job on your backup server downloading once is a lot more straight forward.