Skip to content

Commit

Permalink
Update mongodb-backup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz authored Dec 1, 2023
1 parent af454fe commit 10bc29d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mongodb/mongodb-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ log() {
}

NOW=$(date '+%y-%m-%d-%H%M')
FILE=/etc/backup/${MONGODB_DB}-${NOW}.dump.gz
FILE="/etc/backup/${MONGODB_DB}-${NOW}.dump.gz"
log "Create Backup $FILE"

if [ -n "$MONGODB_USER" ] && [ -n "$MONGODB_PASSWORD" ]; then
URI="mongodb+srv://$MONGODB_USER:$MONGODB_PASSWORD@$MONGODB_HOST"
URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD@$MONGODB_HOST/$MONGODB_DB"
else
URI="mongodb+srv://$MONGODB_HOST"
URI="mongodb://$MONGODB_HOST/$MONGODB_DB"
fi

mongodump --archive=$FILE --gzip --db=$MONGODB_DB --uri="$URI"
# Remove the port number from MONGODB_HOST
MONGODB_HOST=$(echo "$MONGODB_HOST" | cut -d: -f1)

mongodump --archive="$FILE" --gzip --uri="$URI"

0 comments on commit 10bc29d

Please sign in to comment.