~ 1 min read

MongoDump - backup script example

An example script for backing up a database

#!/bin/bash

backupfolder="/backup/mongo/`date +"%Y-%m-%d_%H.%M"`"
db="db_to_backup"

# do the dump
mongodump --uri="mongodb://user:pass@domain:27017/" --db=$db  -v --gzip --out=$backupfolder

# repack with zip - 0 - just basically adding a password...
zip -0 -P alamoAlamo $backupfolder/backup.zip $backupfolder/$db/*.gz 

# cleanup original *.gz files
rm -fR $backupfolder/$db