Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Last active June 23, 2022 11:36
Show Gist options
  • Save ba0f3/e54e5dd290a4598f98c8b20507869977 to your computer and use it in GitHub Desktop.
Save ba0f3/e54e5dd290a4598f98c8b20507869977 to your computer and use it in GitHub Desktop.
backup mongodb using BareOS' bpipe plugin
#!/bin/sh
# Save this file on the on FD
# /usr/lib/bareos/plugins/mongo_bpipe.sh
#DBNAMES=""
#DBUSERNAME=""
#DBPASSWORD=""
#DBAUTHDB=""
OPT="--quiet"
if [ "$DBUSERNAME" ]; then
OPT="$OPT --username=$DBUSERNAME --password=$DBPASSWORD"
if [ "$DBAUTHDB" ]; then
OPT="$OPT --authenticationDatabase=$DBAUTHDB"
fi
fi
if [ -z "$DBNAMES" ]; then
DBNAMES=$(echo "show dbs" | mongo $OPT | awk '{list=list " " $1} END {print list}')
fi
for db in $DBNAMES; do
if [ "$db" != "admin" ] && [ "$db" != "config" ] && [ "$db" != "local" ]; then
for coll in $(mongo $OPT $db --eval "db.getCollectionNames()"| grep \"| awk -F\" '{list=list " " $2} END {print list}'); do
echo "bpipe:/_mongobackups_/$db/$coll.bson:mongodump $OPT --db $db --collection $coll -o -:mongorestore $OPT --db $db --collection $coll -"
done
fi
done
# /etc/bareos/bareos-dir.d/fileset/mongodb.conf
FileSet {
Name = "mongodb"
Include {
Options {
signature = MD5
compression = lz4
}
Plugin = "\\|/usr/lib/bareos/plugins/mongo_bpipe.sh %l"
}
}
# /etc/bareos/bareos-fd.d/client/myself.conf
Client {
...
# Load bpipe plugin
Plugin Names = "bpipe"
...
}
@Theprim0
Copy link

Theprim0 commented Nov 12, 2021

Hello, actually I have the next error on bareos saying:
Fatal error: bpipe-fd: Error closing stream for pseudo file /_mongobackups_/.....

Was trying to find a solution but nothing about bpipe. This is the bpipe code and it prints the error on IO error:
https://fossies.org/linux/bareos/core/src/plugins/filed/bpipe/bpipe-fd.cc

Using Bareos-fd 20.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment