Deep Tech Point
first stop in your tech adventure

Server backup for free

May 19, 2022 | Linux

There are still free things on the internet. You can use free cloud storage for backup copy of your data. Keep in mind that this should be only one layer of your backup solution, others include data copy on your physical backup hard drive. However, free cloud backup is great for daily backup where you will keep only certain amount of copies depending on how big is your backup. Let’s see what options we have regarding server backup for free.

With everything free today on the internet always comes a catch: it’s free until company which provide the service or the storage decides otherwise, but on the other hand can last for years, which can save you considerable amount of money. For example, G Suite legacy free edition will no longer be available after June 27, 2022. These accounts will be automatically transitioned to a paid version ..

You are never sure for how long will company keep some free service available but even if at some point in time it became planned for shut down you will have enough time to migrate your data and change your daily server backup solution.

There are quite a few providers of cloud storage for free, basically requiring only registration and you are ready to go with cloud storage. As a desktop user there are plenty of desktop software which you can easily install and be able to use for access cloud storage. These software will then configure usually virtual drive on your operating system so you can easily copy whatever you need to that drive and it will be automatically transferred to “your” cloud storage. On the other hand there are scriptable command line software solutions that you can use to program customized backups which we will focus on.

In past years many major companies offered cloud storage as one of their product lines and as a kind of promotion offer free storage accounts. Google offers 15GB, MediaFire offers 10GB, etc. There are a plenty of less known companies that also offer cloud storage free accounts up to 200GB. In this tutorial we will use MEGA, company founded by Kim DotCOM, hosted in New Zealand. They offer 20GB of free storage but what’s even more important have a nice set of command line tools we can use to customize and automatize backups. You don’t even need to code shell scripts.

It’s always good to start with web interface because that’s something you might need to access your data easily. So register your free MEGA account. Now when you have activated your account look around cloud storage web interface a bit to familiarize yourself with basic operations. It’s all easy and straight-forward (upload, download, etc).

Now you have to install MEGA command line tools on your server(s). For example, if you have Ubuntu Linux server you will use apt package manager to install MEGA command line tools. Some Linux distributions even have tools packages in their own official repositories for different cloud storages. You can give it a try using:

# apt search mega

, and read the list of packages in hope that one of them will be MEGA tools. Then you can install it with:

# apt install package-name

Keep in mind that some of Linux own repositories have outdated versions of cloud storage tools, so in this tutorial we will use official MEGA tools binaries, you can download from here. Choose your operating system, distribution and version and you will be able to download official MEGA tools package. For example for Ubuntu 18.04 package file will be megacmd-xUbuntu_18.04_amd64.deb and you can install it:

# apt install megacmd-xUbuntu_18.04_amd64.deb

If you can’t find right version in download dropdown menu you can find full list of versions here: https://mega.nz/linux/repo/.

If installation went through, you will end up having bunch of mega tools you can list typing mega- and TAB button. As you should know typing command with argument –help will display short help on how to use the command in question. First command you should use is mega-login which will create session with your MEGA cloud storage account:

# mega-login your@email password

Now you can use one of many MEGA commands. Most of them are actually same as Linux operating system commands (ls, mkdir, cp, mv, etc) but are designed to work with cloud storage.

Examples of commands and usage:

# mega-whoami
Account e-mail: your@email

# mega-session
Your (secret) session is: AQoatcpopgsFSfgR-SqBxz8h2T9xTgndJHxCOdN7m9-0elJxM1RvNEtEUUmQXKVmyCqPSCoOs3T2iKOH

# mega-ls -la
FLAGS VERS    SIZE            DATE       NAME
d---    -          - 17May2022 09:24:18 backup
----    1    1002903 22Feb2022 20:22:40 Welcome to MEGA.pdf

# mega-df -h
Cloud drive:               3.78 GB in      19 file(s) and       4 folder(s)
Inbox:                     0.00  B in       0 file(s) and       0 folder(s)
Rubbish bin:               0.00  B in       0 file(s) and       0 folder(s)
---------------------------------------------------------------------------
USED STORAGE:              3.78 GB                       18.88% of 20.00 GB
---------------------------------------------------------------------------
Total size taken up by file versions:      0.00  B

Instead of typing commands with mega- prefix you could start MEGA console with mega-cmd and be able to type commands without prefix while working with the cloud storage. To exit console type “quit”.

One of the most important commands in mega tools is mega-put. It’s the one to “put” your backup(files) to cloud storage. It’s easy to use like all other commands but keep in mind that you need active session to be able to upload files.

# mega-put --help
Usage: put  [-c] [-q] [--ignore-quota-warn] localfile [localfile2 localfile3 ...] [dstremotepath]
Uploads files/folders to a remote folder

Options:
 -c     Creates remote folder destination in case of not existing.
 -q     queue upload: execute in the background. Don't wait for it to end'
 --ignore-quota-warn    ignore quota surpassing warning.
                          The upload will be attempted anyway.

For interactive upload you will type something like:

# mega-put -c backup.gz.tar backups

Command option -c is always good to have if you are uploading directory structure with multiple files in your backup. Option -q is crucial for non-interactive asynchronous upload, meaning when you’re using mega-put command from your custom backup shell script.

Another very useful command is mega-backup with which you can schedule backing up directories. You are even able to set number of backups this tool will keep on your cloud storage. For example, if your backup’s size is 2GB you can store up to 10 backups:

# mega-backup /path/to/backup /remote/path --period="0 0 4 * * *" --num-backups=10

This command will schedule copy of local directory backup and its content to remote path on MEGA cloud storage every day at 4:00 A.M. (UTC). First backup will be carried out immediately and it will keep last 10 backups. By typing mega-backup you can list configured backups and with option -h you can see the backup history. For more details on controlling backup you can check: https://github.com/meganz/MEGAcmd/blob/master/contrib/docs/BACKUPS.md.

If you need more storage than 20GB there are pay options starting with 400GB for few dollars a month. You can also register additional accounts if you need a bit more than 20GBs and distribute your backups across those accounts. This however requires a little bit of additional programming but it’s completely doable.