Over the last few months I’ve been testing Red Hat’s new PaaS offering, OpenShift. The testing insofar has gone extremely smooth, but what about preparing for when disaster strikes. The rhc command-line client provides snapshot functionality but unfortunately carries the caveat of needing to shut down and restart the application in the process. For a PHP or Python application this is fine as restarts are lightning fast, but redeploying a JavaEE application is… cough… not so lightning fast.
If you can live with the need to restart, this command will give you a very complete tarball:
The other option is to do it via a cron job that will back up the data into your OpenShift data directory on the server (the data in this directory is not deleted each time the application is redeployed). To do this, you will need to have the cron cartridge installed in your application.
If you don’t already have the cron cartridge installed, you can easily enable it with this command:
With cron setup, we can setup jobs to run minutely, hourly, daily, weekly, or monthly by dropping scripts into the appropriate folder in our application’s .openshift/cron directory. Create a file named backup_postgres.sh in the minutely, hourly, daily, weekly, or monthly folder and paste the following script in. (Also available on GitHub)
With the backup script created simply commit it and push the changes to your application.
Once the changes are pushed you can retrieve your application’s database backups by using rsync
This, admittedly, isn’t the prettiest solution to the problem but it does its job. I may end up patching the rhc CLI app to do something similar to this and automatically download the results.