Thursday, January 24, 2013

MongoDB user backup


If you want use this script add new job to CRON.
where:
--host: Host where running MongoDB
-db: database that you want to backup
-c: Use the --collection option to specify the collection that you want mongoexport to export.
-out: place where will be located backup
- If file older then 365 day delete it.





#!/bin/sh
now=$(date +"%m_%d_%Y")

# Test
mongoexport --host 127.0.0.1:10000 -db MYDB-test -c user -out /DATA/test/my.backup-test.$now.json

# QA
mongoexport --host 127.0.0.1:10001 -db MYDB-qa -c user -out /DATA/qa/my.backup-qa.$now.json

# Prod
mongoexport --host 127.0.0.1:10002 -db MYDB-prod -c user -out /DATA/prod/my.backup-prod.$now.json

# Test. Rm files older then 1 year
find /DATA/test/* -mtime +365 -exec rm {} \;

# QA. Rm files older then 1 year
find /DATA/qa/* -mtime +365 -exec rm {} \;

# Prod. Rm files older then 1 year
find /DATA/prod/* -mtime +365 -exec rm {} \;

No comments:

Post a Comment