-
-
Save Theprim0/ddd28fe0c1a7352cda61c7519bf887a6 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