@nka212bg/backend-utils 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/os.js +5 -4
- package/package.json +1 -1
package/os.js
CHANGED
|
@@ -2,7 +2,7 @@ const { execSync } = require("child_process");
|
|
|
2
2
|
const si = require("systeminformation");
|
|
3
3
|
const osUtils = require("os-utils");
|
|
4
4
|
const os = require("os");
|
|
5
|
-
const { statfsSync, readdirSync, existsSync, rmSync, lstatSync } = require("fs");
|
|
5
|
+
const { statfsSync, readdirSync, existsSync, rmSync, lstatSync, mkdirSync } = require("fs");
|
|
6
6
|
const { shortCount, secToTime } = require("./misc");
|
|
7
7
|
const AdmZip = require("adm-zip");
|
|
8
8
|
|
|
@@ -31,20 +31,21 @@ exports.rebootServer = ({ password } = {}) => {
|
|
|
31
31
|
|
|
32
32
|
exports.backupSystem = async ({ basePath, archiveName, overrideExisting, items } = {}) => {
|
|
33
33
|
try {
|
|
34
|
-
if (!items) throw "No items";
|
|
35
|
-
if (typeof items == "string") items = [items];
|
|
36
|
-
|
|
37
34
|
const startTime = Date.now();
|
|
38
35
|
|
|
39
36
|
basePath = basePath || `${__basedir}/backups`;
|
|
40
37
|
archiveName = archiveName || new Date().toISOString().split("T")[0];
|
|
41
38
|
const fullPath = `${basePath}/${archiveName}`;
|
|
39
|
+
!existsSync(basePath) && mkdirSync(basePath, { recursive: true });
|
|
42
40
|
|
|
43
41
|
const availableBackups = readdirSync(basePath);
|
|
44
42
|
if (availableBackups.length > 2) rmSync(`${basePath}/${availableBackups[0]}`, { recursive: true, force: true });
|
|
45
43
|
|
|
46
44
|
if (!overrideExisting && existsSync(`${fullPath}.zip`)) return console.log("backupSystem info, file awready exists --> ", `${fullPath}.zip`);
|
|
47
45
|
|
|
46
|
+
if (!items) throw "No items";
|
|
47
|
+
if (typeof items == "string") items = [items];
|
|
48
|
+
|
|
48
49
|
const zip = new AdmZip();
|
|
49
50
|
items.forEach((e) => (lstatSync(e).isFile() ? zip.addLocalFile(e) : zip.addLocalFolder(e)));
|
|
50
51
|
zip.writeZip(`${fullPath}.zip`);
|