I have mongod
instance running on 1.2.3.4
for example and have another backup server on 100.90.80.1
.
I need to make backup mongodb data from 1.2.3.4
to 100.90.80.1
with the following bash script:
#!/bin/bash
set -e
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="1.2.4.4"
MONGO_PORT="27017"
MONGO_DATABASE="db"
MONGO_USERNAME="login"
MONGO_PASSWORD="pass"
TIMESTAMP=`date +%F-%H%M`
BACKUP_FILE_PATH="/var/backups/tokumx-backup-$TIMESTAMP"
error_exit()
{
echo "Backup TokuMX filed due Error: $1" 1>&2
rm -rf $BACKUP_FILE_PATH
rm -rf $BACKUP_FILE_PATH.tar
exit 1
}
# Create backup
$MONGODUMP_PATH --host $MONGO_HOST --port $MONGO_PORT --db $MONGO_DATABASE --use
rname $MONGO_USERNAME --password $MONGO_PASSWORD --out $BACKUP_FILE_PATH
# Make archive
tar cf $BACKUP_FILE_PATH.tar -C $BACKUP_FILE_PATH/ .
# Remove backup folder
rm -rf $BACKUP_FILE_PATH
But I can't connect to 1.2.3.4
due this option in /etc/mongodb.conf
bind_ip = 127.0.0.1
I know that I may to change the restriction above to bind_ip = 0.0.0.0
but it's not secure.
What is the best way to make secure connections to remote mongod server and backup files to another one with my bash script above?
P.S: I run the script above such as the following:
sudo sh /scripts/tokumx_backup_script