Mar 082013
 

AMANDA is a free and reliable backup system for Linux. Out of the box, it backs up filesystems, MySQL and PostgreSQL. It has a plugin API, and this allows one to write scripts to extend AMANDA’s functionality – to back up a Mongo database, for instance.

To do so, all that is needed is a custom script to perform the necessary database dump and clean-up commands, and some configuration in AMANDA to call this script with the correct arguments. The AMANDA script API is discussed extensively on the official Zmanda Wiki page. The plugin I’ve written, and the procedure discussed, is relevant to Linux only. This won’t work on Windows.

Mongo Backups

There are several ways of backing up a Mongo database, as discussed in the Mongo DB
Documentation. It’s worth reviewing this page before proceeding.

For a small database, the mongodump command will perform adequately, and that is the method that the ammongodb plugin script uses. For larger DBs with heavier IO, filesystem snapshotting (with LVM or ZFS) may be the more suitable solution. A later version of the script will allow this functionality.

Plugin script: ammongodb

The following script ammongodb should be copied to your AMANDA plugin directory, which may be /usr/libexec/amanda/application (depending on the OS you’re using). It can be downloaded from Github, from the link below.
ammongodb on gitub: https://github.com/matthewparsons/ammongodb

AMANDA Configuration

In order to configure AMANDA to use the plugin script, update the configuration-specific amanda.conf file with these blocks.
amanda.conf

    define script-tool script-dump-mongo-replica {
        comment "Execute mongodump script"
        plugin "ammongodb"
        execute-where client
        execute-on pre-dle-backup, post-dle-backup
        property "port" "27018"
        property "auth" "/var/mongo/auth/mongo_backup_auth.cfg"
        property "log" "/var/logs/mongo/mongo-amanda.log"
    }

    define dumptype dump-mongo-replica {
        comp-user-tar
        comment "Mongo Dump"
        script "script-dump-mongo-replica"
        auth "bsdtcp"
    } 

And then, in my disklist file, use the dumptype like this:
disklist

  proddb.example.com  /var/mongo/dump  dump-mongo-replica

Mongo Configuration

Finally, Mongo needs to be permissioned to allow the backup user to login. As from Mongo DB 2.2.2, the backup user cannot be read-only, and needs write access to the admin database.

Create a user with the credentials defined in the “auth” file defined in the amanda.conf file:
/var/mongo/auth/mongo_backup_auth.cfg

USER=backup
PASSWORD=Backup123

Create the same user on the read-only Mongo node’s admin database:

mongo localhost:27018/admin -u admin -p
   mongo> db.addUser("backup","Backup1234",false)

Invoking Backup

Using the AMANDA backup user, amandabackup

  amandabackup$>  amdump DailyDump

If all goes well, this should back up all the compressed Mongo JSON files. To debug any problems, check the AMANDA client sendbackup file, or the logfile (/var/logs/mongo/mongo-amanda.log) defined in the amanda.conf dumptype definition.

Any other queries, I’m happy to respond to in the comments below.


Matt Parsons is a freelance Linux specialist who has designed, built and supported Unix and Linux systems in the finance, telecommunications and media industries.

He lives and works in London.

  One Response to “Mongo DB Backups with AMANDA”

  1. Great article …. thanks mate

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>