Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Global table replication Issue #80 #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions bin/dynamo-backup-to-s3
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ program
.option('--aws-key <key>', 'AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set')
.option('--aws-secret <secret>', 'AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set')
.option('--aws-region <region>', 'AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set')
.option('--strip-fields <list>', '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
Expand All @@ -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);
Expand All @@ -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);
});
});

16 changes: 14 additions & 2 deletions lib/dynamo-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -259,4 +271,4 @@ DynamoBackup.prototype._getDataPipelineAttributeValueKey = function (type) {
}
};

module.exports = DynamoBackup;
module.exports = DynamoBackup;