Introduction
Mega.nz is one of the most affordable cloud storage in terms of volume, because it provides its new users with 50Gb of cloud disk space absolutely free. There are also paid plans that allow you to expand the cloud up to 4 terabytes. But even 50Gb is quite enough for backup copies of sites and MySQL databases. Also, there is a set of megatools console utilities for downloading and uploading files to a remote cloud.
Solution setup
Installing megatools
First, register and activate your mega.nz account if you don’t already have one.
Next, you need to connect to the server via SSH, and install the necessary packages for assembling megatools:
sudo apt-get -y install build-essential libglib2.0-dev libssl-dev libcurl4-openssl-dev libgirepository1.0-dev
After that, you should find a link to download megatools on the official website, which we then use to download with the wget command.
|
|
After we have downloaded and unzipped the source code, we need to compile it. This can be done using the following sequence of commands:
|
|
If everything was compiled and installed without errors, you can proceed to the next stage, namely writing a script for creating and uploading backups to the cloud.
Creating a backup script
First, we create a file with data for logging into the account:
|
|
The file should be filled as follows:
|
|
As our login data is stored unencrypted, let’s make it available only to root.
chmod 640 .megarc
Now let’s check the correctness of entering the login and password, for this we enter the command:
megals
If all settings are correct, it should display a list of files. If the command did not display a list of files, then we check the correctness of entering the password, if it did, then we proceed to the next step of creating a backup script. In this case, the scripts are stored in the /opt/scripts directory with modified permissions.
nano /opt/scripts/do_backup.sh
The script looks like this:
|
|
Now you need to allow the execution of the script:
chmod a+x /opt/scripts/do_backup.sh
Next, you need to test the script by directly executing it:
/opt/scripts/do_backup.sh
After that, you can go to the mega account through the web interface and check that the necessary files have appeared there.
Creating a script autorun rule in crontab
In order for the script to run according to a certain time schedule, let’s add it to the crontab.
04 04 * * * root /opt/scripts/do_backup.sh
Is it optimal to use ?
In my case, the backup folder is 538.8 Mb
in size.
A total of 50,000 Mb
of free space on the cloud. Let each backup weigh approximately 550 Mb
. We divide 50,000 by 550, we have:
50000 / 550 ≈ 90.9
This means that the cloud is enough for 90 backups, which is quite a large number, especially if you take into account the free service of Mega.
But optimality as a whole depends on factors:
- Backup size
- Backup frequency
- Storage duration of each backup
Therefore, it is advisable to evaluate the optimality separately for each individual case.