@datatruck/cli 0.41.11 → 0.41.13
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.
|
@@ -15,10 +15,23 @@ export declare class ResticRepository extends RepositoryAbstract<ResticRepositor
|
|
|
15
15
|
RESTIC_PASSWORD_FILE?: string;
|
|
16
16
|
RESTIC_REPOSITORY: string;
|
|
17
17
|
};
|
|
18
|
+
createEnv(config: ResticRepositoryConfig): Promise<{
|
|
19
|
+
RESTIC_REPOSITORY: string;
|
|
20
|
+
RESTIC_PASSWORD: string;
|
|
21
|
+
} | {
|
|
22
|
+
RESTIC_REPOSITORY: string;
|
|
23
|
+
RESTIC_PASSWORD_FILE: string;
|
|
24
|
+
}>;
|
|
18
25
|
buildEnv(): Promise<{
|
|
19
26
|
RESTIC_PASSWORD?: string;
|
|
20
27
|
RESTIC_PASSWORD_FILE?: string;
|
|
21
28
|
RESTIC_REPOSITORY: string;
|
|
29
|
+
} | {
|
|
30
|
+
RESTIC_REPOSITORY: string;
|
|
31
|
+
RESTIC_PASSWORD: string;
|
|
32
|
+
} | {
|
|
33
|
+
RESTIC_REPOSITORY: string;
|
|
34
|
+
RESTIC_PASSWORD_FILE: string;
|
|
22
35
|
}>;
|
|
23
36
|
static createSnapshotTag(name: SnapshotTagEnum, value: string): string;
|
|
24
37
|
static createSnapshotTags(object: Omit<SnapshotTagObject, "size">): string[];
|
|
@@ -22,15 +22,18 @@ exports.resticRepositoryName = "restic";
|
|
|
22
22
|
class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
23
23
|
static refPrefix = "dt-";
|
|
24
24
|
env;
|
|
25
|
+
async createEnv(config) {
|
|
26
|
+
return {
|
|
27
|
+
...(typeof config.password === "string"
|
|
28
|
+
? { RESTIC_PASSWORD: config.password }
|
|
29
|
+
: { RESTIC_PASSWORD_FILE: (0, path_1.resolve)(config.password.path) }),
|
|
30
|
+
RESTIC_REPOSITORY: await restic_1.Restic.formatRepository(config.repository),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
25
33
|
async buildEnv() {
|
|
26
34
|
if (this.env)
|
|
27
35
|
return this.env;
|
|
28
|
-
return (this.env =
|
|
29
|
-
...(typeof this.config.password === "string"
|
|
30
|
-
? { RESTIC_PASSWORD: this.config.password }
|
|
31
|
-
: { RESTIC_PASSWORD_FILE: (0, path_1.resolve)(this.config.password.path) }),
|
|
32
|
-
RESTIC_REPOSITORY: await restic_1.Restic.formatRepository(this.config.repository),
|
|
33
|
-
});
|
|
36
|
+
return (this.env = await this.createEnv(this.config));
|
|
34
37
|
}
|
|
35
38
|
static createSnapshotTag(name, value) {
|
|
36
39
|
return `${ResticRepository.refPrefix}${name}:${value}`;
|
|
@@ -106,7 +109,12 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
106
109
|
});
|
|
107
110
|
const result = await restic.snapshots({
|
|
108
111
|
tags: [
|
|
109
|
-
...(data.options.ids?.
|
|
112
|
+
...(data.options.ids?.flatMap((id) => id.length === 8
|
|
113
|
+
? [
|
|
114
|
+
ResticRepository.createSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.ID, id),
|
|
115
|
+
ResticRepository.createSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.SHORT_ID, id),
|
|
116
|
+
]
|
|
117
|
+
: ResticRepository.createSnapshotTag(RepositoryAbstract_1.SnapshotTagEnum.ID, id)) ?? []),
|
|
110
118
|
],
|
|
111
119
|
});
|
|
112
120
|
const filterPkg = (0, config_1.createPkgFilter)(data.options.packageNames);
|
|
@@ -204,7 +212,10 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
204
212
|
},
|
|
205
213
|
});
|
|
206
214
|
const [lastSnapshot] = await restic.snapshots({
|
|
207
|
-
tags: [
|
|
215
|
+
tags: [
|
|
216
|
+
packageTag,
|
|
217
|
+
`${ResticRepository.refPrefix}pkg:${data.package.name}`,
|
|
218
|
+
],
|
|
208
219
|
latest: 1,
|
|
209
220
|
});
|
|
210
221
|
const nodePkg = (0, fs_1.parsePackageFile)();
|
|
@@ -285,7 +296,6 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
285
296
|
};
|
|
286
297
|
}
|
|
287
298
|
async copy(data) {
|
|
288
|
-
const config = data.mirrorRepositoryConfig;
|
|
289
299
|
const [snapshot] = await this.fetchSnapshots({
|
|
290
300
|
options: {
|
|
291
301
|
ids: [data.snapshot.id],
|
|
@@ -296,14 +306,14 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
296
306
|
if (!snapshot)
|
|
297
307
|
throw new error_1.AppError(`Snapshot not found`);
|
|
298
308
|
const restic = new restic_1.Restic({
|
|
299
|
-
env: await this.
|
|
309
|
+
env: await this.createEnv(data.mirrorRepositoryConfig),
|
|
300
310
|
log: data.options.verbose,
|
|
301
311
|
});
|
|
302
312
|
let bytes = 0;
|
|
303
313
|
await restic.copy({
|
|
304
314
|
ids: [snapshot.originalId],
|
|
305
|
-
fromRepo: await restic_1.Restic.formatRepository(config.repository),
|
|
306
|
-
fromRepoPassword: config.password,
|
|
315
|
+
fromRepo: await restic_1.Restic.formatRepository(this.config.repository),
|
|
316
|
+
fromRepoPassword: this.config.password,
|
|
307
317
|
onStream(data) {
|
|
308
318
|
if (data.message_type === "status") {
|
|
309
319
|
bytes = data.total_bytes;
|
|
@@ -148,7 +148,10 @@ class AsyncProcess {
|
|
|
148
148
|
this.log = resolveLogOptions($log);
|
|
149
149
|
this.controller = $controller || new AbortController();
|
|
150
150
|
if (this.log?.exec)
|
|
151
|
-
(0, process_1.logProcess)(command, argv || [],
|
|
151
|
+
(0, process_1.logProcess)(command, argv || [], {
|
|
152
|
+
env: options.env,
|
|
153
|
+
...this.log,
|
|
154
|
+
});
|
|
152
155
|
if (typeof options.cwd === "string")
|
|
153
156
|
ensureDir(options.cwd);
|
|
154
157
|
this.child = (0, child_process_1.spawn)(command, argv?.map(String) || [], otherOptions ?? {});
|
package/lib/utils/bytes.js
CHANGED
|
@@ -7,9 +7,9 @@ const sizeRegex = new RegExp(`^(\\d+(?:\\.\\d+)?)\\s*(${units.join("|")})$`, "i"
|
|
|
7
7
|
function formatBytes(inBytes, sign = false) {
|
|
8
8
|
let u = 0;
|
|
9
9
|
let n = Math.abs(inBytes);
|
|
10
|
-
if (n <
|
|
10
|
+
if (n < 0)
|
|
11
11
|
throw new Error(`Invalid bytes: ${n.toString()}`);
|
|
12
|
-
while (n >=
|
|
12
|
+
while (n >= 1024 && ++u)
|
|
13
13
|
n = n / 1024;
|
|
14
14
|
const result = Number(n).toFixed(n < 10 && u > 0 ? 1 : 0) + units[u];
|
|
15
15
|
return inBytes < 0 ? `-${result}` : `${sign ? "+" : ""}${result}`;
|
package/lib/utils/restic.js
CHANGED
|
@@ -259,16 +259,18 @@ class Restic {
|
|
|
259
259
|
], {
|
|
260
260
|
env: {},
|
|
261
261
|
});
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
262
|
+
let snapshotError;
|
|
263
|
+
await copy.stdout.parseLines((line) => {
|
|
264
|
+
if (line.startsWith("{") && line.endsWith("}")) {
|
|
265
|
+
options.onStream?.(JSON.parse(line));
|
|
266
|
+
// https://github.com/restic/restic/issues/5071
|
|
267
|
+
}
|
|
268
|
+
else if (line.includes("failed to load snapshot")) {
|
|
269
|
+
snapshotError = line;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (typeof snapshotError === "string")
|
|
273
|
+
throw new Error(`Failed to load snapshot: ${snapshotError}`);
|
|
272
274
|
}
|
|
273
275
|
catch (e_1) {
|
|
274
276
|
env_1.error = e_1;
|