Created
September 13, 2018 02:02
-
-
Save hanguyen221/45d967cf4039a9daa91d54938014650c to your computer and use it in GitHub Desktop.
To back up & restore from backup for mongodb.
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 | |
# 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