Last active
August 28, 2024 08:18
-
-
Save sheharyarn/0f04c1ba18462cddaaf5 to your computer and use it in GitHub Desktop.
Mongodump Shell Script for Cronjob
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_db_name" | |
APP_NAME="your_app_name" | |
MONGO_HOST="127.0.0.1" | |
MONGO_PORT="27017" | |
TIMESTAMP=`date +%F-%H%M` | |
MONGODUMP_PATH="/usr/bin/mongodump" | |
BACKUPS_DIR="/home/username/backups/$APP_NAME" | |
BACKUP_NAME="$APP_NAME-$TIMESTAMP" | |
# mongo admin --eval "printjson(db.fsyncLock())" | |
# $MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE | |
$MONGODUMP_PATH -d $MONGO_DATABASE | |
# mongo admin --eval "printjson(db.fsyncUnlock())" | |
mkdir -p $BACKUPS_DIR | |
mv dump $BACKUP_NAME | |
tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUP_NAME | |
rm -rf $BACKUP_NAME |
How to delete after 1 week please let me know..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @serverguru666, just wondering does mongoDB authenticationType have anything to do with this error that i get when i try mongodump using your connection format -
2020-05-31T23:53:02.921+0000 Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
NB: The issue is that the command doesn't want me to add
--password
as plaintext, if i remove the--password
flag it prompts me for password and works ok.