@nka212bg/backend-utils 0.1.20 → 0.1.21
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/README.md +0 -0
- package/db/dbUtils.js +0 -0
- package/db/mysql2.js +0 -0
- package/db/sqlite3.js +0 -0
- package/index.js +0 -0
- package/location/GeoLite2-City.mmdb +0 -0
- package/location/VPNs-master.zip +0 -0
- package/location/index.js +0 -0
- package/location/localelib.js +0 -0
- package/mailSmsTools/defaultTemplate.html +0 -0
- package/mailSmsTools/index.js +0 -0
- package/markdown/index.js +0 -0
- package/markdown/markdown.js +0 -0
- package/misc.js +0 -0
- package/os.js +25 -7
- package/package.json +1 -1
- package/session.js +0 -0
- package/socket.js +0 -0
- package/stripe.js +0 -0
- package/systemLog.js +0 -0
package/README.md
CHANGED
|
File without changes
|
package/db/dbUtils.js
CHANGED
|
File without changes
|
package/db/mysql2.js
CHANGED
|
File without changes
|
package/db/sqlite3.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/location/VPNs-master.zip
CHANGED
|
File without changes
|
package/location/index.js
CHANGED
|
File without changes
|
package/location/localelib.js
CHANGED
|
File without changes
|
|
File without changes
|
package/mailSmsTools/index.js
CHANGED
|
File without changes
|
package/markdown/index.js
CHANGED
|
File without changes
|
package/markdown/markdown.js
CHANGED
|
File without changes
|
package/misc.js
CHANGED
|
File without changes
|
package/os.js
CHANGED
|
@@ -29,25 +29,42 @@ exports.rebootServer = ({ password } = {}) => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
exports.backupSystem = async ({ basePath, archiveName,
|
|
32
|
+
exports.backupSystem = async ({ basePath, archiveName, override, items, count = 5 } = {}) => {
|
|
33
33
|
try {
|
|
34
34
|
const startTime = Date.now();
|
|
35
35
|
|
|
36
36
|
basePath = basePath || `${__basedir}/backups`;
|
|
37
|
-
archiveName = archiveName || new Date().toISOString().split("T")[0];
|
|
38
|
-
const fullPath = `${basePath}/${archiveName}`;
|
|
39
37
|
!existsSync(basePath) && mkdirSync(basePath, { recursive: true });
|
|
40
|
-
|
|
38
|
+
|
|
39
|
+
|
|
41
40
|
const availableBackups = readdirSync(basePath);
|
|
42
|
-
if (availableBackups.length >
|
|
41
|
+
if (availableBackups.length > parseInt(count)) {
|
|
42
|
+
let oldestFile = null;
|
|
43
|
+
let oldestTime = Infinity;
|
|
44
|
+
|
|
45
|
+
availableBackups.forEach(file => {
|
|
46
|
+
file = `${basePath}/${file}`;
|
|
47
|
+
const stats = lstatSync(file);
|
|
48
|
+
|
|
49
|
+
if (stats.isFile() && stats.birthtimeMs < oldestTime) {
|
|
50
|
+
oldestTime = stats.birthtimeMs;
|
|
51
|
+
oldestFile = file;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
rmSync(oldestFile, { recursive: true, force: true });
|
|
55
|
+
}
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
archiveName = archiveName || new Date().toISOString().split("T")[0];
|
|
58
|
+
const fullPath = `${basePath}/${archiveName}`;
|
|
59
|
+
|
|
60
|
+
if (!override && existsSync(`${fullPath}.zip`)) return console.log("backupSystem info, file awready exists --> ", `${fullPath}.zip`);
|
|
45
61
|
|
|
46
62
|
if (!items) throw "No items";
|
|
47
63
|
if (typeof items == "string") items = [items];
|
|
48
64
|
|
|
49
65
|
const zip = new AdmZip();
|
|
50
|
-
items.forEach((e) =>
|
|
66
|
+
items.forEach((e) => lstatSync(e).isFile() ? zip.addLocalFile(e) : zip.addLocalFolder(e, e.split('/').pop()));
|
|
67
|
+
|
|
51
68
|
zip.writeZip(`${fullPath}.zip`);
|
|
52
69
|
|
|
53
70
|
console.info(`System backup --> time: ${parseInt((Date.now() - startTime) / 1000)}`);
|
|
@@ -61,6 +78,7 @@ exports.osStatus = () => {
|
|
|
61
78
|
|
|
62
79
|
try {
|
|
63
80
|
return {
|
|
81
|
+
serverStart,
|
|
64
82
|
serverUptime: secToTime((now - serverStart) / 1000),
|
|
65
83
|
machineUptime: secToTime(os.uptime()),
|
|
66
84
|
memoryUsage: shortCount(os.totalmem() - os.freemem(), "disk"),
|
package/package.json
CHANGED
package/session.js
CHANGED
|
File without changes
|
package/socket.js
CHANGED
|
File without changes
|
package/stripe.js
CHANGED
|
File without changes
|
package/systemLog.js
CHANGED
|
File without changes
|