Search code examples
mysqlcronbackupmaster-slavejelastic

Jelastic backup solution


I have an application running on Jelastic and I'm searching for a backup solution. I found this doc about Master-Slave replication.

From what I understand I can have a secondary environment whit a copy of my database in either synchronous or asynchronous way, meaning that the changes to my database will happen at the same time, or queued up and written later.

But let's say I accidentally screwed up and deleted a database or my host has a problem and has to restore a backup, and the only one available is from yesterday (happened to me this week...).

If i delete the database and the changes happen at the same time, I'll lose everything on both environments, or should I use a cron and DUMP to backup my slave database hourly?

If anyone has a better backup solution I'll take it gladly.


Solution

  • The most simple solution in your case is using cron.

    Following this instruction you can easily schedule the automatic backup of a MySQL or MariaDB database.

    A. Setting up backups

    1. Click Config button next to your database.

    create env

    1. In the opened configuration tab open mysql file in the cron folder.

    config

    1. In the opened file you'll see three samples of the cron parameters configurations:

      • for backup of several DBs (if you created them through the db admin panel):

    0 1 * * * /var/lib/jelastic/bin/backup_script.sh -m dump -u USER -p PASSWORD -d db1[,db2,db3....]

    • for separate DB tables backup:

    0 2 * * * /var/lib/jelastic/bin/backup_script.sh -m dump -u USER -p PASSWORD -d db -t table1[,table2,table3....]

    • for the whole DB backup:

    0 3 * * * /var/lib/jelastic/bin/backup_script.sh -m dumpall -u USER -p PASSWORD

    1. Choose the one you need and specify your custom configurations:

      • frequency of the script evoking (using cron settings)
      • the path to the default script (available for MariaDB and MySQL) or to your own (you can upload it to the scripts folder): /var/lib/jelastic/bin/{script_name}
      • your database username and password (you received them in the email after adding database to the environment);
      • if you want to backup several databases or some separate tables, then enter their names separated by commas.

    For example, if you want to backup your database every 10 minutes with a help of the default script, then the string can be as following:

    enter image description here

    1. Save your settings!

    B. Checking backups

    1. Wait the time of backup you've scheduled while setting.
    2. Navigate to Configuration tab and open backup folder (/var/lib/jelastic/backup). There .bz2 files with all executed backups are stored.

    enter image description here

    C. Download Backup

    1. Install FTP for your database. You can find instruction in FTP/FTPS Support guide.

    ftp

    1. Connect to the MySQL/MariaDB database using any FTP client (e.g. FileZilla) and download your backup .bz2 file.

    bz2

    D. Restore Database

    1. Access phpMyAdmin with the credentials you've got after adding DB node.

    2. Navigate to the Import tab and browse the backup .bz2 file. Click Go.

    phpmyadmin

    1. When the import is successfully finished you will see your database with all the data restored.

    restored

    That's all! Now you can be sure that all your data is being saved periodically and can be restored or reused.

    If you need more assistance, do not hesitate to contact us or support team of the chosen hosting provider (click "Help" > "Contact Support" on the top right corner of Jelastic dashboard).

    Good luck and have a nice day.