@datatruck/cli 0.41.12 → 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}`;
|
|
@@ -293,7 +296,6 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
293
296
|
};
|
|
294
297
|
}
|
|
295
298
|
async copy(data) {
|
|
296
|
-
const config = data.mirrorRepositoryConfig;
|
|
297
299
|
const [snapshot] = await this.fetchSnapshots({
|
|
298
300
|
options: {
|
|
299
301
|
ids: [data.snapshot.id],
|
|
@@ -304,14 +306,14 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
304
306
|
if (!snapshot)
|
|
305
307
|
throw new error_1.AppError(`Snapshot not found`);
|
|
306
308
|
const restic = new restic_1.Restic({
|
|
307
|
-
env: await this.
|
|
309
|
+
env: await this.createEnv(data.mirrorRepositoryConfig),
|
|
308
310
|
log: data.options.verbose,
|
|
309
311
|
});
|
|
310
312
|
let bytes = 0;
|
|
311
313
|
await restic.copy({
|
|
312
314
|
ids: [snapshot.originalId],
|
|
313
|
-
fromRepo: await restic_1.Restic.formatRepository(config.repository),
|
|
314
|
-
fromRepoPassword: config.password,
|
|
315
|
+
fromRepo: await restic_1.Restic.formatRepository(this.config.repository),
|
|
316
|
+
fromRepoPassword: this.config.password,
|
|
315
317
|
onStream(data) {
|
|
316
318
|
if (data.message_type === "status") {
|
|
317
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;
|