Last active
June 23, 2022 11:36
-
-
Save ba0f3/e54e5dd290a4598f98c8b20507869977 to your computer and use it in GitHub Desktop.
backup mongodb using BareOS' bpipe plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/bareos/bareos-fd.d/client/myself.conf | |
Client { | |
... | |
# Load bpipe plugin | |
Plugin Names = "bpipe" | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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