@datatruck/restic 0.0.1 → 0.0.3
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/config.schema.json +136 -21
- package/lib/actions/backup.d.ts +38 -36
- package/lib/actions/backup.js +179 -112
- package/lib/actions/base.d.ts +10 -0
- package/lib/actions/base.js +19 -0
- package/lib/actions/copy.d.ts +17 -11
- package/lib/actions/copy.js +99 -109
- package/lib/actions/create.d.ts +10 -0
- package/lib/actions/create.js +49 -0
- package/lib/actions/init.d.ts +3 -8
- package/lib/actions/init.js +34 -49
- package/lib/actions/prune.d.ts +14 -0
- package/lib/actions/prune.js +123 -0
- package/lib/bin.js +2 -57
- package/lib/config.d.ts +49 -6
- package/lib/config.js +47 -0
- package/lib/create-bin.d.ts +3 -0
- package/lib/create-bin.js +83 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +2 -0
- package/lib/utils/async.d.ts +10 -0
- package/lib/utils/async.js +36 -0
- package/lib/utils/fs.d.ts +10 -1
- package/lib/utils/fs.js +39 -2
- package/lib/utils/mysql.d.ts +2 -8
- package/lib/utils/mysql.js +7 -10
- package/lib/utils/ntfy.d.ts +12 -4
- package/lib/utils/ntfy.js +36 -16
- package/lib/utils/string.d.ts +1 -0
- package/lib/utils/string.js +3 -0
- package/package.json +2 -2
- package/lib/utils/restic-backup.d.ts +0 -49
- package/lib/utils/restic-backup.js +0 -91
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { checkDiskSpace } from "./fs.js";
|
|
2
|
-
import { ResticRepository } from "@datatruck/cli/repositories/ResticRepository.js";
|
|
3
|
-
import { formatBytes } from "@datatruck/cli/utils/bytes.js";
|
|
4
|
-
import { duration } from "@datatruck/cli/utils/date.js";
|
|
5
|
-
import { isLocalDir } from "@datatruck/cli/utils/fs.js";
|
|
6
|
-
import { Restic } from "@datatruck/cli/utils/restic.js";
|
|
7
|
-
export class ResticBackup {
|
|
8
|
-
options;
|
|
9
|
-
ntfy;
|
|
10
|
-
log;
|
|
11
|
-
processes = [];
|
|
12
|
-
startTime;
|
|
13
|
-
restic;
|
|
14
|
-
constructor(options, ntfy, log) {
|
|
15
|
-
this.options = options;
|
|
16
|
-
this.ntfy = ntfy;
|
|
17
|
-
this.log = log;
|
|
18
|
-
this.startTime = Date.now();
|
|
19
|
-
this.restic = new Restic({
|
|
20
|
-
env: {
|
|
21
|
-
RESTIC_PASSWORD: options.connection.password,
|
|
22
|
-
RESTIC_REPOSITORY: options.connection.uri,
|
|
23
|
-
},
|
|
24
|
-
log,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async run(input) {
|
|
28
|
-
const items = Array.isArray(input) ? input : [input];
|
|
29
|
-
for (const item of items) {
|
|
30
|
-
await this.runSingle(item);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async runSingle(item) {
|
|
34
|
-
const now = Date.now();
|
|
35
|
-
let error;
|
|
36
|
-
const stats = {
|
|
37
|
-
bytes: 0,
|
|
38
|
-
files: 0,
|
|
39
|
-
diffBytes: undefined,
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
if (isLocalDir(this.options.connection.uri) &&
|
|
43
|
-
!(await this.restic.checkRepository()))
|
|
44
|
-
await this.restic.exec(["init"]);
|
|
45
|
-
const targetPath = isLocalDir(this.options.connection.uri)
|
|
46
|
-
? this.options.connection.uri
|
|
47
|
-
: undefined;
|
|
48
|
-
stats.diffBytes = await checkDiskSpace({
|
|
49
|
-
minFreeSpace: this.options.minFreeSpace,
|
|
50
|
-
minFreeSpacePath: targetPath ?? process.cwd(),
|
|
51
|
-
targetPath,
|
|
52
|
-
rutine: () => {
|
|
53
|
-
const tags = {
|
|
54
|
-
...this.options.tags,
|
|
55
|
-
package: item.name,
|
|
56
|
-
tags: item.tags,
|
|
57
|
-
};
|
|
58
|
-
return this.restic.backup({
|
|
59
|
-
tags: ResticRepository.createSnapshotTags(tags),
|
|
60
|
-
paths: [item.path],
|
|
61
|
-
exclude: item.exclude,
|
|
62
|
-
onStream(data) {
|
|
63
|
-
if (data.message_type === "summary") {
|
|
64
|
-
stats.files = data.total_files_processed;
|
|
65
|
-
stats.bytes = data.total_bytes_processed;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
catch (inError) {
|
|
73
|
-
error = inError;
|
|
74
|
-
}
|
|
75
|
-
this.processes.push({ name: item.name, error, stats });
|
|
76
|
-
await this.ntfy.send(`Backup`, {
|
|
77
|
-
"- Repository": this.options.name,
|
|
78
|
-
"- Package": item.name,
|
|
79
|
-
"- Size": formatBytes(stats.bytes),
|
|
80
|
-
...(stats.diffBytes !== undefined && {
|
|
81
|
-
"- Size change": (stats.diffBytes > 0 ? "+" : "") + formatBytes(stats.diffBytes),
|
|
82
|
-
}),
|
|
83
|
-
"- Files": stats.files,
|
|
84
|
-
"- Duration": duration(Date.now() - now),
|
|
85
|
-
"- Error": error?.message,
|
|
86
|
-
}, {
|
|
87
|
-
priority: error ? "high" : "default",
|
|
88
|
-
tags: [error ? "red_circle" : "green_circle"],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|