Skip to content

Instantly share code, notes, and snippets.

@Theprim0
Forked from ba0f3/mongo_bpipe.sh
Created November 12, 2021 11:58
Show Gist options
  • Save Theprim0/ddd28fe0c1a7352cda61c7519bf887a6 to your computer and use it in GitHub Desktop.
Save Theprim0/ddd28fe0c1a7352cda61c7519bf887a6 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"
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment