mongodb_s3_backup
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -12,3 +12,3 @@ #!/usr/bin/env node | ||
, crontab = "0 0 * * *" | ||
, timezone = "America/New_York" | ||
, timezone = "UTC" | ||
, time = [0, 0] | ||
@@ -15,0 +15,0 @@ , options, configPath, config; |
@@ -13,3 +13,5 @@ { | ||
"bucket": "s3_bucket_to_upload_to", | ||
"destination": "/" | ||
"destination": "/", | ||
"encrypt": true, | ||
"region": "s3_region_to_use" | ||
}, | ||
@@ -16,0 +18,0 @@ "cron": { |
50
index.js
@@ -5,3 +5,5 @@ 'use strict'; | ||
, spawn = require('child_process').spawn | ||
, path = require('path'); | ||
, path = require('path') | ||
, domain = require('domain') | ||
, d = domain.create(); | ||
@@ -71,3 +73,3 @@ /** | ||
} | ||
log("Removing " + target, 'warn'); | ||
log("Removing " + target, 'info'); | ||
exec( 'rm -rf ' + target, callback); | ||
@@ -180,14 +182,16 @@ }); | ||
, s3client | ||
, destination = options.destination || '/'; | ||
, destination = options.destination || '/' | ||
, headers = {}; | ||
callback = callback || function() { }; | ||
s3client = knox.createClient({ | ||
key: options.key, | ||
secret: options.secret, | ||
bucket: options.bucket | ||
}); | ||
// Deleting destination because it's not an explicitly named knox option | ||
delete options.destination; | ||
s3client = knox.createClient(options); | ||
if (options.encrypt) | ||
headers = {"x-amz-server-side-encryption": "AES256"} | ||
log('Attemping to upload ' + target + ' to the ' + options.bucket + ' s3 bucket'); | ||
s3client.putFile(sourceFile, path.join(destination, target), function(err, res){ | ||
s3client.putFile(sourceFile, path.join(destination, target), headers, function(err, res){ | ||
if(err) { | ||
@@ -231,13 +235,17 @@ return callback(err); | ||
, archiveName = getArchiveName(mongodbConfig.db) | ||
, async = require('async'); | ||
, async = require('async') | ||
, tmpDirCleanupFns; | ||
callback = callback || function() { }; | ||
async.series([ | ||
tmpDirCleanupFns = [ | ||
async.apply(removeRF, backupDir), | ||
async.apply(removeRF, path.join(tmpDir, archiveName)), | ||
async.apply(removeRF, path.join(tmpDir, archiveName)) | ||
]; | ||
async.series(tmpDirCleanupFns.concat([ | ||
async.apply(mongoDump, mongodbConfig, tmpDir), | ||
async.apply(compressDirectory, tmpDir, mongodbConfig.db, archiveName), | ||
async.apply(sendToS3, s3Config, tmpDir, archiveName) | ||
], function(err) { | ||
d.bind(async.apply(sendToS3, s3Config, tmpDir, archiveName)) // this function sometimes throws EPIPE errors | ||
]), function(err) { | ||
if(err) { | ||
@@ -248,6 +256,18 @@ log(err, 'error'); | ||
} | ||
return callback(err); | ||
// cleanup folders | ||
async.series(tmpDirCleanupFns, function() { | ||
return callback(err); | ||
}); | ||
}); | ||
// this cleans up folders in case of EPIPE error from AWS connection | ||
d.on('error', function(err) { | ||
d.exit() | ||
async.series(tmpDirCleanupFns, function() { | ||
throw(err); | ||
}); | ||
}); | ||
} | ||
module.exports = { sync: sync, log: log }; |
{ | ||
"name": "mongodb_s3_backup", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A tool to help backup your mongodb databases to s3.", | ||
@@ -23,7 +23,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "~0.1.22", | ||
"cli": "~0.4.4-2", | ||
"cli-color": "~0.2.1", | ||
"cron": "~1.0.1", | ||
"knox": "~0.8.0", | ||
"cli-color": "~0.2.1", | ||
"async": "~0.1.22", | ||
"cron": "~1.0.1" | ||
"time": "^0.11.2" | ||
}, | ||
@@ -30,0 +31,0 @@ "engines": { |
@@ -29,3 +29,5 @@ # Node MongoDB / S3 Backup | ||
"bucket": "s3_bucket_to_upload_to", | ||
"destination": "/" | ||
"destination": "/", | ||
"encrypt": true, | ||
"region": "s3_region_to_use" | ||
}, | ||
@@ -37,2 +39,4 @@ "cron": { | ||
All options in the "s3" object, except for desination, will be directly passed to knox, therefore, you can include any of the options listed [in the knox documentation](https://github.com/LearnBoost/knox#client-creation-options "Knox README"). | ||
### Crontabs | ||
@@ -53,3 +57,3 @@ | ||
The optional "timezone" allows you to specify timezone-relative time regardless | ||
of local timezone on the host machine. | ||
of local timezone on the host machine. | ||
@@ -56,0 +60,0 @@ "cron": { |
11555
303
73
6
+ Addedtime@^0.11.2
+ Addedbindings@1.2.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedms@2.0.0(transitive)
+ Addednan@2.19.0(transitive)
+ Addedtime@0.11.4(transitive)