I want to create a script to backup a collection in MongoDB on a daily basis. I want it to be run at 00:30 every day to backup data that has been inserted to this collection during the day before. When I do this manually I run it like this:
mongodump -d History -c history -q '{ czas: { $gte: new Date(1443571201000), $lte: new Date(1443657540000)} }' --out /home/test/backup
now I want those unix timestamp to be generated automatically. In a bash this command makes the trick:
TZ=UTC date --date="`date +"%Y-%m-%d 00:00:00" -d '1 day ago'`" +"%s"
But I dont know how to combine it in a mongodb command. This command fails:
mongodump -d History -c history -q '{ czas: { $gte: new Date(`date --date="`date +"%Y-%m-%d 00:00:00" -d '2 days ago'`" +"%s"`), $lte: new Date(`date --date="`date +"%Y-%m-%d 00:00:00" -d '1 day ago'`" +"%s"`)} }' --out /home/test/backup
with a message:
2015-11-26T16:45:03.051+0100 positional arguments not allowed: [days ago`" +"%s"`), $lte: new Date(`TZ=UTC date --date="`date +"%Y-%m-%d 00:00:00" -d 1 day ago`" +"%s"`)} }]
I'm not unix guru, please help me how to get this working.
Regards, Przemek