Archive/backup your server with Mega and megatools / CentOS 7

I am Mega user for quite some time now. I have VPS on which I run my blog. Idea was: can I upload my blog/website/database backups to my Mega account daily? So I wish to use Mega as some sort of backup service. It is possible as there is Linux tool that allows operations through your Linux machine to your Mega account. It is called megatools. Mega offers 50G of capacity for free! In most cases, this should be more than enough to backup your websites. You can backup your server to your Mega account! Downside is, that megatools currently don’t offer function such as is rsync – for archive purposes.

Here is how to install megatools – in this case, on CentOS 7:

  1. You should install some dependencies that megatools is using first.
    yum -y install gcc make glib2-devel libcurl-devel openssl-devel gmp-devel tar
  2. Download megatools archive (latest version can be found HERE)
    [root@vps ~]# wget
  3. Unpack package and go to  megatools directory.
    [root@vps ~]# tar xvzf megatools-1.9.97.tar.gz
  4. Install Megatools
    [root@vps megatools-1.9.97]# ./configure
    Configured features:
    docs build: no
    warnings: no
    megafs: no (requires fuse)
    tests: yes (requires glib-2.0 >= 2.34.0)
    Run make now.
    [root@vps megatools-1.9.97]# make
    [root@vps megatools-1.9.97]# make install
  5. Megatools is installed. Now you should configure it so that will be able to access you Mega account. In your root directory, create file .megarc, that will contain your login information.
    [root@vps ~]# vi .megarc 
    add this:
    Username = UsernameOrEmail
    Password = MyPassword
    [root@vps ~]# chmod 600 .megarc
  6. Check if megatools can connect to your Mega account
    [root@vps ~]# megadf -h
    Total: 50.0 GiB
     Used: 2.9 GiB
     Free: 47.1 GiB

How to use megatools, you can see here. Bellow is simple example how to create new directory on our Mega account that will be used for our server archive files. Copy is done with command megacopy. Command megacopy won’t overwrite existing files nor will delete them.

  1. Create directory for our backup archives on our Mega account:
    [root@vps ~]# megamkdir /Root/BACKUP
    [root@vps ~]# megamkdir /Root/BACKUP/myarchive
  2. Copy files to our newly created Mega archive directory
    [root@vps ~]# megacopy --local /var/www/mywebpage/ --remote /Root/BACKUP/myarchive/
    F /Root/BACKUP/myarchive/public_html/wp-content/uploads/2014/10/000_0776-300x194.jpg
    F /Root/BACKUP/myarchive/public_html/wp-content/uploads/2014/10/000_0776-900x582.jpg
    F /Root/BACKUP/myarchive/public_html/wp-content/uploads/2014/10/000_0776.jpg
    F /Root/BACKUP/myarchive/public_html/wp-content/uploads/2014/10/000_0785-144x144.jpg
     100% - 11.6 KiB of 11.6 KiB

You can schedule this operations by adding this lines to your crontab. For example, if you want to copy document root directory of your website daily, you add this to your crontab:

* 0 * * * /usr/local/bin/megacopy --local /var/www/mywebpage/ --remote /Root/BACKUP/myarchive/ >/dev/null 2>&1

I will also create some script for this in the future! 🙂



Got Something To Say:

Your email address will not be published.


I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Thanks for your great tutorial

I flow your every step & successfully done. I’m using VPS, centos 7 & WHM panel. I have one domain hosted in my VPS, i want to just backup my full website & database . please check screenshot url , i just stack here . where i input cron job..?

I have questions to you below

1. need backup run in my WHM panel for go to data from my server to mega account? just this point i cann’t understand.

Please help he.

Lookingforward yourearlier response

    Hello ashik. You can create crontab with executing this in your command line: crontab -e. If you have shared hosting account, than you’ll need to be able to create crontab and megatools installed. You’ll probably have to have root privileges. As root install megatools and then create crontab with command that will execute megatools to copy data to Mega.


      Thanks for your response.

      I’m using VPS not shared . please check the screenshot , i did added my server home. is it ok or not..?

      Listen, i want to backup my server whole domain, like if i add future another one domain. i need that domain backup, database , email.

      Please help me step by step.


Your guide is one of the best available. I’ve been working with Linux for several years now and it is rare to find a guide that works from start to finish. One tiny bit of advice I do have for you: You could suggest people to download megatools to their bin or sbin folder or something they have in their $PATH already. then they don’t have to use ./ to run it. Other than that: Well done and thank you for saving me time and headaches 🙂

megatools-1.9.97 use asciidoc:

yum -y install gcc make glib2-devel libcurl-devel openssl-devel gmp-devel tar asciidoc

On Centos there is a package in EPEL repository megatools-1.9.98-6.el7.x86_64.
#yum install megatools

© 2022
Hosted by SIEL

About author