From d2f633524beb4df60fbc079d01d101761012c1ab Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 15 Sep 2023 03:50:12 +0600 Subject: [PATCH 1/2] Fix docs Signed-off-by: Vladimir --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed8d99e..4bceacf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Super Easy backups -- Easy to set up (about 5 minutes) -- Removes old backups (backups rotation), saving space on your device -- Multiple annual, monthly, weekly backups by your choice +- #### Easy to set up (about 5 minutes) +- #### Removes old backups (backups rotation), saving space on your device +- #### Multiple annual, monthly, weekly backups by your choice Tested on: Windows 11, Ubuntu 22.02 From 6615db71670e0e0438bd10e9cc5e32c4c7faf32c Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 15 Sep 2023 04:34:57 +0600 Subject: [PATCH 2/2] Linter+error fix Signed-off-by: Vladimir --- .eslintrc.json | 6 +++--- package.json | 3 ++- src/class/FolderBackup.js | 43 ++++++++++++++++++--------------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index e662839..6fcd59f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,12 +20,12 @@ { "singleQuote": true } - ] + ], // "default-case": "warn", // "no-param-reassign": "off", // "no-console": "off", // "prefer-const": "warn", - // "no-var": "warn", + "no-var": "warn" // "semi": "warn", // "padded-blocks": "warn", // "space-before-blocks": "warn", @@ -34,4 +34,4 @@ "plugins": [ "prettier" ] -} \ No newline at end of file +} diff --git a/package.json b/package.json index ca05d87..b9bab7a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "lint:fix": "npm run lint -- --fix", "prettier": "npx prettier src test --check", "prettier:fix": "npm run prettier -- --write", - "format": "npm run prettier:fix && npm run lint:fix" + "format": "npm run prettier:fix && npm run lint:fix", + "compose-tests": "docker-compose -f docker-compose-tests.yml up --build" }, "author": { "name": "CodeLit", diff --git a/src/class/FolderBackup.js b/src/class/FolderBackup.js index b956775..c4aa41a 100644 --- a/src/class/FolderBackup.js +++ b/src/class/FolderBackup.js @@ -22,7 +22,7 @@ export default class FolderBackup { } static formatISODate(date) { - let params = {}; + const params = {}; params.dd = String(date.getDate()).padStart(2, '0'); params.mm = String(date.getMonth() + 1).padStart(2, '0'); params.yyyy = date.getFullYear(); @@ -31,7 +31,8 @@ export default class FolderBackup { async init() { // fm - file manager - let fmImport = await import('./storage_base/' + this.type + '.js'); + const fmImport = await import('./storage_base/' + this.type + '.js'); + this.fm = new fmImport.default(this.options); switch (this.type) { @@ -93,15 +94,15 @@ export default class FolderBackup { async makeBackups(count = 3, type) { logger.log(_.capitalize(type) + ' backups started.'); const pathToBackups = path.normalize(this.pathToBackups + '/' + type); - let date = FolderBackup.formatISODate(this.today); + const date = FolderBackup.formatISODate(this.today); - let pathToBackup = path.normalize(pathToBackups + '/bkp_' + date + '.tgz'); + const pathToBackup = path.normalize( + pathToBackups + '/bkp_' + date + '.tgz', + ); if (!this.fm.exists(pathToBackups)) await this.fm.makeDir(pathToBackups); - logger.log('Backups destination folder created.'); - - let files = this.fm.readDir(pathToBackups) || []; + let files = (await this.fm.readDir(pathToBackups)) || []; let doNotCreate = false; @@ -110,8 +111,8 @@ export default class FolderBackup { fileDate = new Date(fileDate[0]); if (type === 'weekly') { - let week = currentWeekNumber(this.today); - let week2 = currentWeekNumber(fileDate); + const week = currentWeekNumber(this.today); + const week2 = currentWeekNumber(fileDate); if (week === week2) { doNotCreate = true; break; @@ -129,10 +130,10 @@ export default class FolderBackup { } } - let tmpBackupDir = path.normalize( + const tmpBackupDir = path.normalize( tempDirectory + '/' + randomString.generate(), ); - let tmpArchiveDir = path.normalize( + const tmpArchiveDir = path.normalize( tempDirectory + '/' + randomString.generate(), ); @@ -143,32 +144,28 @@ export default class FolderBackup { filter: this.filter, }); - logger.log('Project Directory was copied to temp folder.'); - if (!this.fm.exists(pathToBackup) && !doNotCreate) { - let tmpArchive = path.normalize(tmpArchiveDir + '/temp.tgz'); + const tmpArchive = path.normalize(tmpArchiveDir + '/temp.tgz'); await tar(tmpBackupDir, tmpArchive, { compression: COMPRESSION_LEVEL.high, }); - logger.log('Temporary archive created.'); - await this.fm.copy(tmpArchive, pathToBackup); - - logger.log('Files copied (or uploaded) to backup destination.'); } fs.rmSync(tmpBackupDir, { recursive: true }); fs.rmSync(tmpArchiveDir, { recursive: true }); - logger.log('Temporary directories removed.'); + files = (await this.fm.readDir(pathToBackups)) || []; - let countFilesToRemove = files.length - count; + const countFilesToRemove = files.length - count; - for (let i = 0; i < countFilesToRemove; i++) { - let fileToRemove = path.normalize(pathToBackups + '/' + files[i]); - await this.fm.rmFile(fileToRemove); + if (files.length > 0) { + for (let i = 0; i < countFilesToRemove; i++) { + const fileToRemove = path.normalize(pathToBackups + '/' + files[i]); + await this.fm.rmFile(fileToRemove); + } } logger.log(_.capitalize(type) + ' backups is done.');