Last active
September 22, 2020 02:44
-
-
Save ThienTranDuy/592823de447e702aa016db1bc784646a to your computer and use it in GitHub Desktop.
Cronjob backup 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/bash | |
MONGO_DATABASE="your_database_name" | |
MONGO_HOST="127.0.0.1" | |
MONGO_PORT="your_mongo_port(default 27017)" | |
USERNAME="your_admin" | |
PASSWORD="your_password" | |
TIMESTAMP=`date +%F-%H%M%S` | |
BACKUP_NAME="$MONGO_DATABASE-$TIMESTAMP" | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
BACKUPS_DIR="/home/backup/mongodb/$BACKUP_NAME" | |
$MONGODUMP_PATH --host=$MONGO_HOST --port=$MONGO_PORT --username=$USERNAME --password=$PASSWORD --out=$BACKUPS_DIR | |
tar -zcvf $BACKUPS_DIR.tar.gz $BACKUPS_DIR | |
rm -rf $BACKUPS_DIR | |
## setup crontab 0 0 */1 * * /usr/bin/bash /home/cronjob/mongo-backup.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment