diff --git a/bin/dynamo-backup-to-s3 b/bin/dynamo-backup-to-s3 index d06b72b..432c7ba 100755 --- a/bin/dynamo-backup-to-s3 +++ b/bin/dynamo-backup-to-s3 @@ -29,6 +29,8 @@ program .option('--aws-key ', 'AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set') .option('--aws-secret ', 'AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set') .option('--aws-region ', 'AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set') + .option('--strip-fields ', 'exclue these fields in the bakup', list) + .option('-g, --global-table', 'specify if global table, will strip aws fields from backup') .parse(process.argv); // run program @@ -46,9 +48,12 @@ var dynamoBackup = new DynamoBackup({ readPercentage: program.readPercentage, stopOnFailure: program.stopOnFailure, base64Binary: program.base64EncodeBinary, + stripFields: program.stripFields, + globalTable: program.globalTable, saveDataPipelineFormat: program.saveDataPipelineFormat }); + dynamoBackup.on('error', function(data) { console.log('Error backing up ' + data.tableName); console.log(data.error); @@ -68,7 +73,13 @@ dynamoBackup.on('end-backup', function(tableName) { console.log('Done copying table ' + tableName + '. Took ' + endTime.diff(startTime, 'minutes', true).toFixed(2) + ' minutes'); }); -dynamoBackup.backupAllTables(function() { - console.log('Finished backing up DynamoDB'); +dynamoBackup.backupAllTables(function(err) { + if(err){ + console.log("Error "+ err); + } + else{ + console.log('Finished backing up DynamoDB'); + } process.exit(0); -}); \ No newline at end of file +}); + diff --git a/lib/dynamo-backup.js b/lib/dynamo-backup.js index a81e469..cfdea39 100644 --- a/lib/dynamo-backup.js +++ b/lib/dynamo-backup.js @@ -26,6 +26,13 @@ function DynamoBackup(options) { this.awsSecretKey = options.awsSecretKey; this.awsRegion = options.awsRegion; this.debug = Boolean(options.debug); + this.stripFields = options.stripFields || []; + this.globalTable = options.globalTable || false; + + if(this.globalTable){ + var awsFields = ['aws:rep:updateregion', 'aws:rep:deleting', 'aws:rep:updatetime']; + this.stripFields = _.union(awsFields, this.stripFields); + } if (this.awsRegion) { params.region = this.awsRegion; @@ -89,7 +96,12 @@ DynamoBackup.prototype.backupTable = function (tableName, backupPath, callback) tableName, function (items) { items.forEach(function (item) { - if (self.base64Binary) { + + self.stripFields.forEach(function(key) { + delete item[key] + }); + + if (self.base64Binary) { _.each(item, function (value, key) { if (value && value.B) { value.B = new Buffer(value.B).toString('base64'); @@ -259,4 +271,4 @@ DynamoBackup.prototype._getDataPipelineAttributeValueKey = function (type) { } }; -module.exports = DynamoBackup; \ No newline at end of file +module.exports = DynamoBackup;