DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Renzo Castillo
Renzo Castillo

Posted on

How to create scheduled cloud backups of your database using mega with webmin

Hi! The procedure to create a scheduled backup in the cloud with webmin is divided into the following steps:

  1. Configuration and installation of the mega command line tool (megatools): To install megatools, configure it with your mega.co.nz account, and know how to use 'megaput' and 'megarm', I recommend you to follow the instructions in this post. Once you have finish the installation and configuration of mega tools, I recommend doing a couple of tests with megaput and megarm of any file they have on their server to test if their configuration was well done.

  2. Configuring webmin to accept dates in the file name: We need another configuration to make webmin agree to run this type of override, otherwise it will think that the name that is placed in our file will be 'static'. For this case we will use the following unix date format:% Y-% m-% d. This should respond to the year, month and day respectively. First we go to Webmin -> Servers -> MySQL Database Server. Then at the top left we find a module configuration button and select it to see more advanced options. Here we look for the option Dostrftimesubstitution of backup destinations? Yes, and we save.

  3. Configuring scheduled database backups: In this case, the first thing we will do is go to the management panel of our database server, which for this case will be MySQL. We then go to Webmin-> Servers -> MySQL Database Server. Once here, we select the database of our interest and we click Backup Database. Here we will configure the following parameters.

  • Backup destination: We select 'path on server' and here we must make sure to indicate a route with parameters based on date format. Therefore our absolute path to place would be:

/ any-directory/%Y-%m-%d-mi-data-base.sql.gz

  • Other backup options:Β  Here I recommend selecting compression by gzip. In addition to this, the commands to debug and upload each backup file to the mega cloud were executed here.

  • Command to run before backup:

rm "/ any-directory /" $ (date -d "$ date -3 days" + "% Y-% m-% d") - my-database.sql.gz && megarm --config = /root/.secrets/mega.cnf "/ Root / my-mega-folder /" $ (date -d "$ date -14 days" + "% Y-% m-% d") - my-base-of -data.sql.gz
Enter fullscreen mode Exit fullscreen mode

Now we will break this command down into 2 parts:

rm "/ any-directory /" $ (date -d "$ date -3 days" + "% Y-% m-% d") - my-database.sql.gz
Enter fullscreen mode Exit fullscreen mode

This command basically removes the backup from the server that is 3 days old, this in order to optimize resources and retain fewer backups.

megarm --config = / root / .secrets / mega.cnf "/ Root / my-mega-folder /" $ (date -d "$ date -14 days" + "% Y-% m-% d") - my-database-sql.gz
Enter fullscreen mode Exit fullscreen mode

This other command removes from the mega directory all those backups that are from 14 days ago, this because generally you will want to have older backups in the cloud.

  • Command to run after backup:
megaput --config = / root / .secrets / mega.cnf --path = / Root / Yaku.app / DEV / backups --disable-previews "/ backups /" $ (date +% Y-% m-% d ) -my-database-sql.gz
Enter fullscreen mode Exit fullscreen mode

This command is executed after the backup is created on the server in the indicated folder, and its purpose is to send the generated backup to the MEGA cloud.

Backup schedule:

  • Send backup status email to: Here we place an email to which we would like the backup confirmation to reach us
  • Send email for: Here we will mark 'Only on failure' so that they do not reach us all the time, only in case the backup fails.
  • Scheduled backup enabled? Yes, at times chosen below ..Simple schedule ..Daily (at midnight)

Once these options are selected, we click 'Save' and save our configuration.

If everything has gone well, the backups should start to be generated and you can view them directly in your Mega account as well as on your webmin server.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.