@datatruck/cli 0.41.10 → 0.41.11
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResticRepositoryUri } from "../utils/restic";
|
|
1
|
+
import { ResticRepositoryUri, ResticSnapshot } from "../utils/restic";
|
|
2
2
|
import { RepositoryAbstract, RepoBackupData, RepoInitData, RepoRestoreData, RepoFetchSnapshotsData, Snapshot, SnapshotTagObject, SnapshotTagEnum, RepoPruneData, RepoCopyData } from "./RepositoryAbstract";
|
|
3
3
|
export type ResticRepositoryConfig = {
|
|
4
4
|
password: string | {
|
|
@@ -26,7 +26,7 @@ export declare class ResticRepository extends RepositoryAbstract<ResticRepositor
|
|
|
26
26
|
name: SnapshotTagEnum;
|
|
27
27
|
value: string;
|
|
28
28
|
} | null;
|
|
29
|
-
static parseSnapshotTags(tags: string[]): SnapshotTagObject;
|
|
29
|
+
static parseSnapshotTags(tags: string[], snapshot: ResticSnapshot): SnapshotTagObject;
|
|
30
30
|
getSource(): string;
|
|
31
31
|
fetchDiskStats(config: ResticRepositoryConfig): Promise<import("../utils/fs").DiskStats | undefined>;
|
|
32
32
|
init(data: RepoInitData): Promise<void>;
|
|
@@ -14,6 +14,7 @@ const restic_1 = require("../utils/restic");
|
|
|
14
14
|
const string_1 = require("../utils/string");
|
|
15
15
|
const temp_1 = require("../utils/temp");
|
|
16
16
|
const RepositoryAbstract_1 = require("./RepositoryAbstract");
|
|
17
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
18
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
18
19
|
const promises_1 = require("fs/promises");
|
|
19
20
|
const path_1 = require("path");
|
|
@@ -49,16 +50,21 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
49
50
|
static parseSnapshotTag(tag) {
|
|
50
51
|
for (const metaName in RepositoryAbstract_1.SnapshotTagEnum) {
|
|
51
52
|
const name = RepositoryAbstract_1.SnapshotTagEnum[metaName];
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const tagNames = [name];
|
|
54
|
+
if (name === RepositoryAbstract_1.SnapshotTagEnum.PACKAGE)
|
|
55
|
+
tagNames.push("pkg");
|
|
56
|
+
for (const tagName of tagNames) {
|
|
57
|
+
const prefix = `${ResticRepository.refPrefix}${tagName}:`;
|
|
58
|
+
if (tag.startsWith(prefix))
|
|
59
|
+
return {
|
|
60
|
+
name: name,
|
|
61
|
+
value: tag.slice(prefix.length),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
return null;
|
|
60
66
|
}
|
|
61
|
-
static parseSnapshotTags(tags) {
|
|
67
|
+
static parseSnapshotTags(tags, snapshot) {
|
|
62
68
|
const result = {
|
|
63
69
|
tags: [],
|
|
64
70
|
};
|
|
@@ -71,6 +77,9 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
71
77
|
result.tags.push(tag);
|
|
72
78
|
}
|
|
73
79
|
}
|
|
80
|
+
result[RepositoryAbstract_1.SnapshotTagEnum.SHORT_ID] ??= result[RepositoryAbstract_1.SnapshotTagEnum.ID].slice(0, 8);
|
|
81
|
+
result[RepositoryAbstract_1.SnapshotTagEnum.HOSTNAME] ??= snapshot.hostname;
|
|
82
|
+
result[RepositoryAbstract_1.SnapshotTagEnum.DATE] ??= (0, dayjs_1.default)(snapshot.time).format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
|
|
74
83
|
return result;
|
|
75
84
|
}
|
|
76
85
|
getSource() {
|
|
@@ -103,7 +112,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
|
|
|
103
112
|
const filterPkg = (0, config_1.createPkgFilter)(data.options.packageNames);
|
|
104
113
|
const filterTask = (0, config_1.createTaskFilter)(data.options.packageTaskNames);
|
|
105
114
|
return result.reduce((items, item) => {
|
|
106
|
-
const tag = ResticRepository.parseSnapshotTags(item.tags ?? []);
|
|
115
|
+
const tag = ResticRepository.parseSnapshotTags(item.tags ?? [], item);
|
|
107
116
|
if (!tag.id)
|
|
108
117
|
return items;
|
|
109
118
|
if (!filterPkg(tag.package))
|
package/lib/utils/fs.js
CHANGED
|
@@ -616,7 +616,7 @@ async function checkFreeDiskSpace(stat, inSize) {
|
|
|
616
616
|
const humanSize = typeof inSize === "number" ? (0, bytes_1.formatBytes)(inSize) : inSize;
|
|
617
617
|
const size = typeof inSize === "number" ? inSize : (0, bytes_1.parseSize)(inSize);
|
|
618
618
|
if (stat.free < size)
|
|
619
|
-
throw new Error(`Free disk space is less than ${humanSize}: ${(0, bytes_1.formatBytes)(stat.free)}/${(0, bytes_1.formatBytes)(stat.total)}`);
|
|
619
|
+
throw new Error(`Free disk space is less than ${humanSize}: ${(0, bytes_1.formatBytes)(stat.total - stat.free)}/${(0, bytes_1.formatBytes)(stat.total)}`);
|
|
620
620
|
}
|
|
621
621
|
async function ensureFreeDiskSpace(input, inSize) {
|
|
622
622
|
if (Array.isArray(input)) {
|
package/lib/utils/restic.d.ts
CHANGED
|
@@ -9,6 +9,17 @@ export type ResticRepositoryUri = {
|
|
|
9
9
|
};
|
|
10
10
|
backend: "local" | "rest" | "sftp" | "s3" | "azure" | "gs" | "rclone";
|
|
11
11
|
} & Omit<Uri, "password">;
|
|
12
|
+
export type ResticSnapshot = {
|
|
13
|
+
time: string;
|
|
14
|
+
tree: string;
|
|
15
|
+
paths: string[];
|
|
16
|
+
tags?: string[];
|
|
17
|
+
hostname: string;
|
|
18
|
+
username: string;
|
|
19
|
+
excludes: string[];
|
|
20
|
+
id: string;
|
|
21
|
+
short_id: string;
|
|
22
|
+
};
|
|
12
23
|
export type ResticBackupStream = {
|
|
13
24
|
message_type: "status";
|
|
14
25
|
seconds_elapsed?: number;
|
|
@@ -94,17 +105,7 @@ export declare class Restic {
|
|
|
94
105
|
json?: boolean;
|
|
95
106
|
group?: ("path" | "tags" | "host")[];
|
|
96
107
|
args?: string[];
|
|
97
|
-
}): Promise<
|
|
98
|
-
time: string;
|
|
99
|
-
tree: string;
|
|
100
|
-
paths: string[];
|
|
101
|
-
tags?: string[];
|
|
102
|
-
hostname: string;
|
|
103
|
-
username: string;
|
|
104
|
-
excludes: string[];
|
|
105
|
-
id: string;
|
|
106
|
-
short_id: string;
|
|
107
|
-
}[]>;
|
|
108
|
+
}): Promise<ResticSnapshot[]>;
|
|
108
109
|
backup(options: {
|
|
109
110
|
cwd?: string;
|
|
110
111
|
tags?: string[];
|