How to Automatic Backup Database on Openshift

Cron is UNIX/Linux service or daemon to execute scheduled commands according to instruction in a file. It uses a daemon, crond, which runs constantly in the background and checks every minute/ hour/ day/ week/ month or an year (based on the configuration) to see if any of the scheduled jobs need to be executed; if so, it executes them. These jobs are generally referred to as cron jobs.

Openshift Cronjob

You can use the OpenShift Enterprise cron scheduler to set up timed jobs for your applications. This would need a running Openshift application, a cron cartridge (cron-1.4) and a cronjob script.

You can automatic backup snapshot or mysql database:

First: You need create an account from openshift, its free limit 3 small gear for testing code…

  1. $ rhc app create -a app -t php-5.3

Second: Enable Crontab on your App

  1. rhc app cartridge add -a app -c cron-1.4

Third: Go to Crontab to configure it

  1. cd app-root/runtime/repo/.openshift/crontab
  2. //daily hourly minutely monthly README.cron weekly >> Choose an folder to set it auto run backup job

Last: Choose an folder to set it auto run backup job,  I have test on daily auto backup job.

  1. cd daily
  2. nano bk
  3. //Copy and paste the bak script.
  4. mysqldump -h $OPENSHIFT_MYSQL_DB_HOST -P $OPENSHIFT_MYSQL_DB_PORT -ppassword -u username yourdata > /var/lib/openshift/xxxxxxxxxx/yourpath/$OPENSHIFT_GEAR_NAME.sql
  5. chmod a+x bk
  6. ./bk