MEGATOOLS – Synchronizing your backups to MEGA

Posted on Posted in linux, VPS

Hi and wellcome to another Sysadmin & DBA tips, in this post We’ll use the MEGATOOL utility to synchronize your server backups to the mega cloud!!


Like the official webpage says:

Megatools is a collection of programs for accessing Mega service from a command line of your desktop or server.
Megatools allow you to copy individual files as well as entire directory trees to and from the cloud. You can also perform streaming downloads for example to preview videos and audio files, without needing to download the entire file.
You can register account using a ‘megareg’ tool, with the benefit of having true control of your encryption keys.
Megatools are robust and optimized for fast operation – as fast as Mega servers allow. Memory requirements and CPU utilization are kept at minimum.

The options that this tool offer:


  megareg      Register and verify a new mega account
  megadf       Show your cloud storage space usage/quota
  megals       List all remote files
  megamkdir    Create remote directory
  megarm       Remove remote file or directory
  megamv       Move and rename remote files
  megaput      Upload individual files
  megaget      Download individual files
  megadl       Download file from a "public" Mega link
               (doesn't require login)
  megastream   Streaming download of a file
               (can be used to preview videos or music)
  megasync     Upload or download a directory tree
  megafs       Mount remote filesystem locally.


Differents installations are possible, in my case I’ll explain how realize a installation in a Ubuntu Server. But if you prefer, you can install from sources, obtain the latest source code from git, or extrac directly the binary files from:

PPA installation

  • Add Megattols PPA repositories to your /etc/apt/sources.list
deb quantal main
deb-src quantal main
  • Import Megatols PPA public Key
add-apt-repository ppa:megous/ppa
  • Update
aptitude update
  • Install megatools
aptitude install megatools


The next step, if you don’t have an account yet, is create one following this steps:

# megareg -n  -e  -p  --agree 
Registration email was sent to ''.
To complete registration, enter signup link bellow.

Enter signup link for, or press CTRL+C:ÑKSdjlasjd klasjlaNhegxSvGAJKLSDNASJKasdnjkaYUBhbGJlcnRvASdlñjkaiops2b20JdHdlZASLKASOPdas54

The account was registered successfully!

Now to simplificate the use of the tool, create a new file in the user account that will be used for megatools utility, or a new global configuration file in /etc that will use with –config=PATH option.

# cat /root/.megarc 
Username =
Password = yourpassword

Finally install this packages:

aptitude install glib-networking gobject-introspection curl libcurl4-gnutls-dev

Now, check if your mega account is accesible from your server using the tool megals:

# megals

Using the tools

Is the moment for see what offer the megatools utility

  • megadf: Show total available, used, or free space in the cloud
# megadf --mb
Total: 51200
Used: 6339
Free: 44860
  • megadl: download exported files and directories from

Download exported file:

$ megadl '!7YVWhCzZ!bauBlAkKKvv8hIm-8-qFmGOYS289ToQWN7rGFPzXB_w'

Download exported folder:

$ megadl '!HIlFDajT!HLiVvQQkSe1d0ogxZuaOJg'
  • megadf: Mount remote filesystem locally via FUSE
$ mkdir -p mount
$ megafs mount
$ ls mount
Contacts Inbox Root Trash
  • megamkdir:  Create remote folder under your account

Create new folder:

$ megamkdir /Root/MyNewFolder
$ megals /Root

Add new contact to your contacts list:

$ megamkdir /Contacts/
  • megamv: move or rename files or folders on your account

Rename a file:

$ megals /Root
$ megamv /Root/README.TXT /Root/README
$ megals /Root

Move file to a another folder:

$ megals -R /Root
$ megamv /Root/README /Root/MyFolder
$ megals -R /Root
  • megaput: upload files to your account

Upload file to the /Root:

$ megaput README
$ megals /Root

Upload file, while naming it differently:

$ megaput --path /Root/README.TXT README
$ megals /Root
  • megasync: Upload/download entire directories to/from your account

Upload directory.

$ megasync --local MyBackups --remote /Root/Backups

Download directory.

$ megasync --local MyBackups --remote /Root/Backups --download

MegaSync script

Mega don’t offer posibility to maintain a real-sync , for example, If I remove a file in my server and launch the megasync utility, MEGA not removed the file on the cloud, having a dirty cloud. To resolve it, I created a personal script that I share with you.


BACKUP_TIME=`date +%c`

#Obtain the files that not exists in the local server

DELETE=`$MEGASYNC --dryrun --reload --download --local $LOCALDIR --remote $REMOTEDIR | sed 's/F '$SEDLOCALDIR'/'$SEDREMOTEDIR'/g'`

# And remove it

for i in $DELETE; do
        $MEGARM $i

# Run the synchronization to Mega

SYNC=`$MEGASYNC --no-progress --local $LOCALDIR --remote $REMOTEDIR`

echo "[$BACKUP_TIME][$(hostname)] synchronization to mega done!!" > $LOG
echo "Files removed $DELETE" >> $LOG
echo "Files synchronized" >> $LOG

4 thoughts on “MEGATOOLS – Synchronizing your backups to MEGA

  1. Hello,
    Thank you for this tool. It succesfully works on my ubuntu box, but it is not working it in my freebsd box (FreeBSD 8.3-RELEASE-p7 i386). I builded it from source megatools-1.9.91.tar.gz and when i run command, for example:
    # megadf
    I got error message:
    GLib-GIO-Message: Using the ‘memory’ GSettings backend. Your settings will not be saved or shared with other applications.
    ERROR: Can’t login to API ‘us’ failed: HTTP POST failed: Connection failed: Unacceptable TLS certificate

    Can you help to resolve this issue ?

  2. I tried to uploading a directory:

    $ megasync –local MyBackups –remote /Root/Backups

    Doesn’t work:

    Remote directory not found /Root/Backups

  3. Alberto, thanks a bunch for the script.
    According to, megasync is now called megacopy.
    I’ve updated your script accordingly, and used a different delimiter for ‘sed’ to simplify configuration.



    BACKUP_TIME=`date +%c`

    #Obtain the files that not exists in the local server

    DELETE=`$MEGACOPY --dryrun --reload --download --local $LOCALDIR --remote $REMOTEDIR | sed 's|F '$LOCALDIR'|'$REMOTEDIR'|g'`

    # And remove it

    for i in $DELETE; do
    $MEGARM $i

    # Run the synchronization to Mega

    SYNC=`$MEGACOPY --no-progress --local $LOCALDIR --remote $REMOTEDIR`

    echo "[$BACKUP_TIME][$(hostname)] synchronization to mega done!!" > $LOG
    echo "Files removed $DELETE" >> $LOG
    echo "Files synchronized" >> $LOG

Leave a Reply

Your email address will not be published. Required fields are marked *