Export / Backup mongo db to cloud storage
Published on 12.06.2014
I'm using Digital Ocean for my experiments and place to host some sites, they provide very good service for ridiculous price but SSD space is limited and for backup purposes I'm using cloud service providers like pCloud. Here are a sample command for backuping Mongo databases to pCloud service.
cd /tmp/ && rm -rf mongo_dump && mkdir mongo_dump && mongodump --out /tmp/mongo_dump/ && tar -cvzf mongo_production_eureka.tar.gz mongo_dump/ && rm -r mongo_dump/ && curl -F "[email protected]" -F "password=password" -F "folderid=0" -F "filename=mongo1.tar.gz" -F "file=@/tmp/mongo_production_eureka.tar.gz" https://api.pcloud.com/uploadfile && rm mongo_production_eureka.tar.gz
For backup only:
cd /tmp/ && rm -rf mongo_dump && mkdir mongo_dump && mongodump --out /tmp/mongo_dump/ && tar -cvzf mongo_production_eureka.tar.gz mongo_dump/ && rm -r mongo_dump/
Our sys admin helped me to make this variant as bash script:
#!/bin/bash set -e dumpdir=mongodb.$$.$RANDOM trap "rm -rf /tmp/$dumpdir /tmp/$dumpdir.tar.gz" exit SIGHUP SIGINT SIGTERM cd /tmp rm -rf $dumpdir mkdir $dumpdir mongodump --out /tmp/$dumpdir tar czf $dumpdir.tar.gz mongo_dump/ curl -F "[email protected]" -F "password=pas1" -F "folderid=0" -F "filename=mongo1.tar.gz" -F "file=@/tmp/$dumpdir.tar.gz" https://api.pcloud.com/uploadfile
More information about pCloud can be viewed in their website http://pcloud.com and Developer documentation
ps: pCloud have versioning of file and for that I'm using one name for all backups.