Actually, there are many way to backup your database. You can using RSYNC, MongoDump for Mongo, S3 Backup Plugin for ElasticSearch. However, this post will show you the way I used in my project. Maybe, It is not perfect for all case. But in my case, it is really perfect.
I am running a project with Microservice Architecture. All Databases and Services are running in Docker Container. In my plan, I have to backup all databases every night.
At the beginning, I tried to use tar
command to compress the data, and then I use command aws s3 copy
to copy backup data to S3. It seems work. But tar
command makes MongoDB stop working. I tried to google to solve the problem. I found the solution is rsync
command.
The backup process should be implement in three steps:
- Use
rsync
command to copy the data to other location - Compress the data by
tar
command - Move the compressed data to AWS S3
The script should be:
1 2 3 4 |
echo Backup MongoDb Data ... rsync -avz /var/lib/docker/volumes/backend_mongodb/ /tmp/mongodb && \ tar cvzf mongodb-${dt}.tar.gz /tmp/mongodb/ && \ aws s3 cp mongodb-${dt}.tar.gz s3://prjbackups/${env}/mongodb/mongodb-${dt}.tar.gz |
Thanks for your reading.