Easy Automated Syncing of MySQL/MariaDB Backup using MEGASync

Mega is a cloud storage and file hosting service offered by Mega Limited, an Auckland-based company. The service is offered primarily through web-based apps. Mega is known for its security feature where all files are end-to-end encrypted locally before they are uploaded. This prevents anyone (including employees of Mega Limited) from accessing the files without knowledge of the passkey used for encryption. The service is noted for a large 50 GB storage allocation for free accounts.

Following are some of the key features of the MEGA cloud service:
  • 50 GB free cloud storage
  • End to end encryption
  • Available on all platforms be it Linux, Windows, Mac OS X or mobile platforms like Android and iOS
  • Selective sync
  • Available in a web browser

Installing MEGA in Linux

Unlike Google Drive, MEGA not only offers a generous 50 GB of free storage, but it also offers a native desktop client for Linux. Binaries are available to easily install MEGASync (desktop sync client for MEGA) in all major Linux desktop. You can get the binary package for MEGASync to form the link below. Just choose your Linux distribution (or the distribution on which your Linux OS is based on).MEGASync client is very similar in function to Dropbox client.

Download MEGAsync

1. Create an account in MEGAsync and sign in



2. Create a folder "MEGAsync" in Linux user home and a folder full_MySQL in the mega cloud. Where we have to point MySQL/MariaDB backup destination. Files deposited in the MEGASync folder will also save in full_MySQL folder of mega cloud storage. ( I have also created two other folders for my Koha & Wordpress)


Set Sync permission to appropriate folders in settings of MEGAsync



Automate MySQL/MariaDB backup 

Open Applications > Accessories > Terminal

Apply the following command,

crontab -e

It will ask to select a text editor. You can select the Nano text editor.
Use the down arrow button and move the cursor to the bottom part of the cron file. Copy & paste the following command there. the backup is scheduled at every 04.30 PM

For entire MySQL/MariaDB backup

30 16 * * * mysqldump -uroot -padmin@lib --all-databases --single-transaction --quick --lock-tables=false | xz > /home/mahesh/MEGAsync/full_MySQL/full-backup.sql.xz

For Koha_library database backup

30 16 * * * mysqldump -uroot -padmin@lib koha_library | xz > /home/mahesh/MEGAsync/koha_backup/koha_library.sql.xz

For Wordpress database backup

30 16 * * * mysqldump -uroot -padmin@lib wordpress | xz > /home/mahesh/MEGAsync/wordpress/wordpress.sql.xz

Change the MySQL/MariaDB password and the destination folder location.

Apply  Ctrl + o button to save the file.

Then apply Ctrl + x to leave the cron.

OR

You can create a BASH script and put that into crontab -e

I created a BASH script which I named as "uploadtomega"

sudo nano /usr/local/bin/uploadtomega.sh

added the following

#!/bin/bash

mysqldump -uroot -padmin@lib --all-databases --single-transaction --quick --lock-tables=false | xz > /home/mahesh/MEGASync/full_MySQL/full-backup-$(date +%d-%m-%Y-%H.%M).sql.xz

mysqldump -uroot -padmin@lib koha_library | xz > /home/mahesh/MEGASync/koha_backup/koha_library-$(date +%d-%m-%Y-%H.%M).sql.xz


mysqldump -uroot -padmin@lib wordpress | xz > /home/mahesh/MEGASync/wordpress/wordpress-$(date +%d-%m-%Y-%H.%M).sql.xz


save it. and change the mod

sudo chmod a+x /usr/local/bin/uploadtomega.sh

Setup a root user cron job with crontab -e and adding the following line and saving it.

30 16 * * * /usr/local/bin/uploadtomega.sh

You can find the backup file in /home/mahesh/MEGAsync/ folder after every 4.30 pm and that will sync to MEGASync folders too.

Refrerence: https://help.ubuntu.com/community/CronHowto#Crontab_Example
                  

0 Komentar