Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb backup script

I need to run mongodump on my database everyday.

How do I automate this reasonably? Every day I want a new folder created with the timestamp and the dump data inside.

Thanks.

like image 914
Harry Avatar asked Dec 09 '25 20:12

Harry


2 Answers

Look at

https://github.com/micahwedemeyer/automongobackup

Otherwise use standard tools like cron or shell scripting for wrapping the mongodump call.

I have a super quick handy script. Sometimes I create a cron job for one of my database.

ssh root@hostname "mongodump --db myDatabaseName --out /tmp/mongo-backup ; zip -r /tmp/mongo-backup$(date "+%Y.%m.%d").zip  /tmp/mongo-backup ; rm -rf /tmp/mongo-backup" ;
scp root@hostname:/tmp/mongo-backup$(date "+%Y.%m.%d").zip ./

The above script does two things.

  1. Runs the mongodump script and builds a ZIP file like: mongo-backup2017.03.02.zip
  2. Downloads that file via SCP to your local machine.
like image 32
ankitjaininfo Avatar answered Dec 11 '25 19:12

ankitjaininfo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!