Skip to content

Instantly share code, notes, and snippets.

@andretapxure
Last active October 8, 2020 21:04
Show Gist options
  • Select an option

  • Save andretapxure/6ded3045adb1f021022e415bc2325e47 to your computer and use it in GitHub Desktop.

Select an option

Save andretapxure/6ded3045adb1f021022e415bc2325e47 to your computer and use it in GitHub Desktop.
SH version of mongobackup
!/bin/bash
rm -rf /mongotemp
mkdir /mongotemp
mongodbs=$(/usr/bin/mongo --quiet --eval "printjson(db.adminCommand('listDatabases'))" | grep name | cut -d: -f2 | cut -d\" -f2)
for db in $mongodbs
do
echo "Backing Up $db "
/usr/bin/mongodump --out=/mongotemp --db=$db
done
zip -r /mongobackup/mongo_$(date +"%Y-%m-%d") /mongobackup
aws s3 sync /mongobackup s3://nectarb/mongodbvalentina --profile backup
find /mongobackup -mtime +5 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment