I want to switch from MySQL to MongoDB but great data losses (more than 1 hour) are not acceptable for me.
I need to have 3 backup plans:
Hourly
DB host (secondary preferred as to avoid impacting primary performance)
HOST='SomeHost/mongodbtest-slave'
DB name
DBNAME=***
S3 bucket name BUCKET=*-backup
Linux user account
USER=ubuntu
Current time
TIME=/bin/date +%d-%m-%Y-%T
Password
PASSWORD=somePassword#!2*1
Username
USERNAME=someUsername
Backup directory DEST=/home/ubuntu/tmp
Tar file of backup directory TAR=$DEST/../$TIME.tar
Create backup dir (-p to avoid warning if already exists) /bin/mkdir -p $DEST
Log echo "Backing up $HOST/$DBNAME to s3://$BUCKET/ on $TIME";
Dump from mongodb host into backup directory
Create tar of backup directory /bin/tar cvf $TAR -C $DEST .
Upload tar to s3 /usr/bin/aws s3 cp $TAR s3://$BUCKET/
Remove tar file locally /bin/rm -f $TAR
Remove backup directory /bin/rm -rf $DEST
All done echo "Backup available at https://s3.amazonaws.com/$BUCKET/$TIME.tar
You can use the steps above put them in a shell executable file and execute this at any interval using crontab commands.