OnApp provides the ready-to-use tool for database backing up - /onapp/onapp-cp-install/onapp-database-dump.sh. This tool is a part of onapp-cp-install package, so it is mandatory for every Control Panel. It is configured as a cron job to dump the OnApp database regularly. Also, this tool is used by the CP installer (onapp-cp-install.sh) to dump the OnApp database before any upgrade.

To set dumping properties, the tool reads the following configuration files:


FileUsage
/onapp/interface/config/database.yml

specifies MySQL/MariaDB connection properties, like: database, host, password, port, username.

/onapp/interface/config/on_app.yml specifies whether SSH File Transfer Server is used: use_ssh_file_transfer, ssh_file_transfer_server, ssh_file_transfer_user, ssh_file_transfer_options, backups_path.
/onapp/onapp-cp.conf

specifies:

  • extra configuration ( e.g. custom dump server)and connection option to it ( e.g. DB_DUMP_SERVER, DB_DUMP_USER, DB_DUMP_SERVER_ROOT, DB_DUMP_SERVER_SSH_OPT) 

  • files rotating option (KEEP_DUMPS)

  • crontab configuration (DB_DUMP_CRON)

  • the path on CP for temporary dumps, accordingly to /onapp/interface (ONAPP_DB_DUMP_ROOT)


When to run?

The tool is configured as a cron job to run hourly. This could be customized in DB_DUMP_CRON variable (/onapp/onapp-cp.conf):

  • The default value is "40 * * * * "
  • Set any other crontab-styled value or leave it blank to disable the job. 
  • Pass the "-D" option to the CP installer (onapp-cp-install-sh). This will:
     disable database dumping during CP install/upgrade;
     make sure that dumping is disabled in the cron;
     make sure no cron job is running during install/upgrade.

How many copies to store?

The number of stored dumps is configured by KEEP_DUMPS variable. The default value is "168" (store 24 dumps per day, and keep for a week). 

The variable value should be set before the CP installer runs.

Where to store dumps?

The dumps are temporarily stored on the Control Panel server in the /onapp/interface/$ONAPP_DB_DUMP_ROOT directory. The directory /onapp/interface/db/dump is set by default. The ONAPP_DB_DUMP_ROOT variable value could be changed in the /onapp/onapp-cp.conf file.
It is possible to move dumps into remote box automatically and to rotate there. The remote box could be:

  • SSH File Transfer Server if enabled in the OnApp configuration. The backups will be moved into server's backups_path directory and rotated there. The dumps are removed from the CP box if transfer to a remote box is successful.


  • Any custom box. It could be configured via DB_DUMP_SERVER in the /onapp/onapp-cp.conf. The backups will be moved into the server's DB_DUMP_SERVER_ROOT directory and rotated there. The dumps are removed from the CP box if transfer to a remote box is successful. 

The custom box should be accessible via ssh from the CP box using onapp user without specifying the password.

To back up the entire OnApp database, use the Linux mysqldump command:

#mysqldump -p onapp > onapp.sql
CODE

To backup a standalone table, use the following syntax replacing table_name with the name of the table to be backed up:

#mysqldump -p onapp table_name > onapp.table_name.sql
CODE

To find the required MySQL password, use the following command:

#cat /onapp/interface/config/database.yml | grep pass
CODE