Last active
February 2, 2017 02:49
-
-
Save keithics/fd53431b6f57014249ca to your computer and use it in GitHub Desktop.
Mongodump and Amazon Glacier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependencies. | |
*/ | |
var mongoose = require('mongoose'), | |
AWS = require('aws-sdk'), | |
exec = require('child_process').exec, | |
fs = require('fs'), | |
name = new Date().toISOString(); | |
/** | |
* Create a MongoDump and upload it to Amazon Glacier | |
*/ | |
exports.dump = function(req, res) { | |
AWS.config.update({region: 'ap-northeast-1'}); | |
var glacier = new AWS.Glacier(); | |
var destination = 'mongodump/'+name; | |
var mongodump = 'mongodump --username USERNAME --password PASSWORD --out '+destination+' --db DATABASE'; | |
var zip = 'zip -r '+destination+'.zip '+destination; | |
var deleteFolder = 'rm -rf '+destination; | |
function puts(error, stdout, stderr) { | |
var file = fs.readFileSync(destination+".zip"); | |
var params = {vaultName: 'VAULT_NAME', body: file}; | |
glacier.uploadArchive(params, function(err, data) { | |
if (err){ | |
console.log("Error uploading archive!", err); | |
} | |
else{ | |
//delete zip file | |
exec(deleteFolder+".zip", function(){ | |
// | |
}); | |
console.log("Archive ID", data.archiveId); | |
} | |
res.send("ok"); | |
}); | |
} | |
exec(mongodump +' && ' +zip+' &&' + deleteFolder, puts); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't seem like mongoose dependency is necessary here?