Skip to content

Instantly share code, notes, and snippets.

@hanguyen221
Created September 13, 2018 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanguyen221/45d967cf4039a9daa91d54938014650c to your computer and use it in GitHub Desktop.
Save hanguyen221/45d967cf4039a9daa91d54938014650c to your computer and use it in GitHub Desktop.
To back up & restore from backup for mongodb.
#! /bin/sh
# replace with address of folder that contains backups
DIR=/Users/nguyen.thanh.ha/Desktop/backupmongo
# remove all backups older than 30 days
find $DIR -mtime +30 -exec rm -rf {} \;
# create new backup for today
mongodump -h <host>:<port> --db <db name> -u <user name> -p <password> --out $DIR/`date +"%Y-%m-%d-%H%M%S"`
# restore
mongorestore -h <host>:<port> --db <db name> --drop -u <user name> -p <password> <backup folder>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment