You can create a database backup and transfer it to a S3 bucket.
First, install s3cmd:
sudo yum --enablerepo epel install s3cmd
#to configure s3cmd
s3cmd --configure
Then create a backup routine in a backup.sh
file:
#!/bin/bash
#Force file syncronization and lock writes
mongo admin --eval "printjson(db.fsyncLock())"
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="prod.example.com"
MONGO_PORT="27017"
MONGO_DATABASE="dbname"
TIMESTAMP=`date +%F-%H%M`
S3_BUCKET_NAME="bucketname"
S3_BUCKET_PATH="mongodb-backups"
# Create backup
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE
# Add timestamp to backup
mv dump mongodb-$HOSTNAME-$TIMESTAMP
tar cf mongodb-$HOSTNAME-$TIMESTAMP.tar mongodb-$HOSTNAME-$TIMESTAMP
# Upload to S3
s3cmd put mongodb-$HOSTNAME-$TIMESTAMP.tar s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/mongodb-$HOSTNAME-$TIMESTAMP.tar
#Unlock databases writes
mongo admin --eval "printjson(db.fsyncUnlock())"
When you run bash backup.sh
a new file will be created like mongodb-localhost-10-10-2013.tar
On the remote server you can use a wget
to download file from Amazon S3.
Extract backup file using tar
like tar -xvf backupname.tar
.
To restore you can use:
mongorestore --dbpath <database path> <directory to the backup>
Like this:
mongorestore --dbpath /var/lib/mongo backup_directory_name
I hope this is enough to help you