MongoDB Backup with the Bacula bpipe Plugin

Just as an illustration, the dash (-) character can be used to generate the backup of Mongo banks directly to the standard output captured by bpipe, but it is necessary to specify the collection (table) for each flow:

mongodump --db hfaria --collection teste -o -
mongodump --db hfaria --collection teste2 -o -

The dash can also be used in the mongorestore command to read the standard input during the beep restore of the bacula:

mongorestore --db hfaria --collection teste -

It is possible to use a script in the Zimbra Client from FileSet to automatically list all databases and create bpipe configuration lines for Bacula.

Example of File Set Include:

\\| /opt/bacula/scripts/mongo_bpipe.sh

Sample mongo_bpipe.sh script:

#
# Authorship: Heitor Faria (Copyleft: all rights reversed).
# Testado por: xxxx
#
# It must be called in the INCLUDE sub-resource of the FileSet of bacula-dir.conf, referring to the client backup installed on the Mongo machine (for example):
#
# Plugin = "\\|/etc/bacula/mongo_bpipe.sh %l"
#

for db in $(echo "db.adminCommand( { listDatabases: 1 } )" | mongo --quiet | grep name | cut -d " -f 4); do
  for coll in $(echo "use $db" | mongo --quiet; echo "show collections" | mongo --quiet); do
    echo "bpipe:/opt/bacula/working/$db_$coll:mongodump --db $db --collection $coll -o -:mongorestore --db $db --collection $coll -"
  done
done

The restoration will be done automatically for MongoDB, if the named pipe is selected to restore.

Alternatively, collections can be restored to disk by changing the command to “dd of=file”.

 

Disponível em: pt-brPortuguês (Portuguese (Brazil)) enEnglish esEspañol (Spanish)

Leave a Reply

Close Menu