Skip to content

Commit

Permalink
Merge pull request #248 from dappnode/hotfix_backup_limit
Browse files Browse the repository at this point in the history
Remove file size limit in backup transfers
  • Loading branch information
eduadiez authored Aug 7, 2019
2 parents 6bfd0cc + 4fea195 commit 3a5869d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 49 deletions.
46 changes: 0 additions & 46 deletions build/src/src/calls/backupGet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use strict"; // 'datauri' requested to use 'use strict';
const params = require("params");
const path = require("path");
const logs = require("logs.js")(module);
Expand All @@ -11,7 +10,6 @@ const dockerList = require("modules/dockerList");
const shell = require("utils/shell");
const validateBackupArray = require("utils/validateBackupArray");

const maxSizeKb = 10e3;
const tempTransferDir = params.TEMP_TRANSFER_DIR;

/**
Expand Down Expand Up @@ -65,19 +63,6 @@ const backupGet = async ({ id, backup }) => {
if (!successfulBackups.length)
throw Error(`Could not backup any item: ${lastError.stack}`);

/**
* Limit max file size until a DAppNode <-> client transport method is adopted
* $ du -s -k app/file.gz
* 12 app/file.gz
*/
const dirSizeKb = await getFileOrDirSize(backupDir);
if (dirSizeKb > 200e3) {
await shell(`rm -rf ${backupDir}`);
throw Error(
`Dir file transfers > ${maxSizeKb} KB are not allowed. Attempting ${dirSizeKb} KB`
);
}

/**
* Use the -C option to cd in the directory before doing the tar
* Provide the list of directories / files to include to keep the file structure clean
Expand All @@ -90,19 +75,6 @@ const backupGet = async ({ id, backup }) => {
await shell(`tar -czf ${backupDirComp} -C ${backupDir} ${dirListToComp}`);
await shell(`rm -rf ${backupDir}`);

/**
* Limit max file size until a DAppNode <-> client transport method is adopted
* $ du -s -k app/file.gz
* 12 app/file.gz
*/
const fileSizeKb = await getFileOrDirSize(backupDirComp);
if (fileSizeKb > 20e3) {
await shell(`rm -rf ${backupDirComp}`);
throw Error(
`File transfers > ${maxSizeKb} KB are not allowed. Attempting ${fileSizeKb} KB`
);
}

const fileId = crypto.randomBytes(32).toString("hex");

await db.set(fileId, backupDirComp);
Expand All @@ -127,22 +99,4 @@ const backupGet = async ({ id, backup }) => {
}
};

// Utility

/**
* Limit max file size until a DAppNode <-> client transport method is adopted
* $ du -s -k app/file.gz
* 12 app/file.gz
* @param {string} path "app/file.gz"
* @returns {string} size in KB "12"
*/
async function getFileOrDirSize(path) {
const output = await shell(`du -s -k ${path}`);
const sizeString = output
.trim()
.replace(/\t/g, " ")
.split(" ")[0];
return parseInt(sizeString || "0");
}

module.exports = backupGet;
3 changes: 2 additions & 1 deletion build/src/src/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = {
userActionLogsFilename: path.join(DNCORE_DIR, "userActionLogs.log"),
// lowdb requires an absolute path
DB_PATH: path.resolve(DNCORE_DIR, "dappmanagerdb.json"),
TEMP_TRANSFER_DIR: path.join(DNCORE_DIR, ".temp-transfer"),
// Temp transfer dir must not be in a volume
TEMP_TRANSFER_DIR: path.join("./", ".temp-transfer"),

// Docker compose parameters
DNS_SERVICE: "172.33.1.2",
Expand Down
3 changes: 1 addition & 2 deletions build/src/test/backup.test.int.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe("Integration test for backup to and from:", function() {
const dockerComposePath =
"dnp_repo/test-backup.dnp.dappnode.eth/docker-compose.yml";

const filePath =
"DNCORE/.temp-transfer/test-backup.dnp.dappnode.eth_backup.tar.xz";
const filePath = ".temp-transfer/test-backup.dnp.dappnode.eth_backup.tar.xz";

/**
* RESTORE => GET integral test
Expand Down

0 comments on commit 3a5869d

Please sign in to comment.