fix: single item file restore (#634)
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
Some checks failed
Release Workflow / determine-release-type (push) Has been cancelled
Release Workflow / checks (push) Has been cancelled
Release Workflow / e2e-tests (push) Has been cancelled
Release Workflow / build-images (push) Has been cancelled
Release Workflow / publish-release (push) Has been cancelled
fix: single item file restore test(e2e): restore single file at custom location Closes #633
This commit is contained in:
parent
3d2900ab69
commit
d660c8e2e4
6 changed files with 76 additions and 4 deletions
|
|
@ -2240,6 +2240,7 @@ export type RestoreSnapshotData = {
|
||||||
excludeXattr?: Array<string>;
|
excludeXattr?: Array<string>;
|
||||||
include?: Array<string>;
|
include?: Array<string>;
|
||||||
overwrite?: 'always' | 'if-changed' | 'if-newer' | 'never';
|
overwrite?: 'always' | 'if-changed' | 'if-newer' | 'never';
|
||||||
|
selectedItemKind?: 'dir' | 'file';
|
||||||
targetPath?: string;
|
targetPath?: string;
|
||||||
};
|
};
|
||||||
path: {
|
path: {
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ export function RestoreForm({ repository, snapshotId, returnPath, basePath }: Re
|
||||||
body: {
|
body: {
|
||||||
snapshotId,
|
snapshotId,
|
||||||
include: includePaths.length > 0 ? includePaths : undefined,
|
include: includePaths.length > 0 ? includePaths : undefined,
|
||||||
|
selectedItemKind: includePaths.length === 1 ? (selectedPathKind ?? undefined) : undefined,
|
||||||
excludeXattr: excludeXattrArray && excludeXattrArray.length > 0 ? excludeXattrArray : undefined,
|
excludeXattr: excludeXattrArray && excludeXattrArray.length > 0 ? excludeXattrArray : undefined,
|
||||||
targetPath,
|
targetPath,
|
||||||
overwrite: overwriteMode,
|
overwrite: overwriteMode,
|
||||||
|
|
@ -145,6 +146,7 @@ export function RestoreForm({ repository, snapshotId, returnPath, basePath }: Re
|
||||||
restoreLocation,
|
restoreLocation,
|
||||||
customTargetPath,
|
customTargetPath,
|
||||||
selectedPaths,
|
selectedPaths,
|
||||||
|
selectedPathKind,
|
||||||
overwriteMode,
|
overwriteMode,
|
||||||
restoreSnapshot,
|
restoreSnapshot,
|
||||||
]);
|
]);
|
||||||
|
|
|
||||||
|
|
@ -375,6 +375,7 @@ export const overwriteModeSchema = type.valueOf(OVERWRITE_MODES);
|
||||||
export const restoreSnapshotBody = type({
|
export const restoreSnapshotBody = type({
|
||||||
snapshotId: "string",
|
snapshotId: "string",
|
||||||
include: "string[]?",
|
include: "string[]?",
|
||||||
|
selectedItemKind: dumpPathKindSchema.optional(),
|
||||||
exclude: "string[]?",
|
exclude: "string[]?",
|
||||||
excludeXattr: "string[]?",
|
excludeXattr: "string[]?",
|
||||||
delete: "boolean?",
|
delete: "boolean?",
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,20 @@ describe("restore command", () => {
|
||||||
expect(getOptionValues("--include")).toEqual([]);
|
expect(getOptionValues("--include")).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("restores a single selected file from its parent directory for non-root targets", async () => {
|
||||||
|
const { getRestoreArg, getOptionValues } = setup();
|
||||||
|
const options: Parameters<typeof restore>[3] & { selectedItemKind: "file" } = {
|
||||||
|
organizationId: "org-1",
|
||||||
|
include: ["/var/lib/zerobyte/volumes/vol123/_data/archive/backup.20260301-233001.7z"],
|
||||||
|
selectedItemKind: "file",
|
||||||
|
};
|
||||||
|
|
||||||
|
await restore(config, "snapshot-single-file", "/tmp/restore-target", options);
|
||||||
|
|
||||||
|
expect(getRestoreArg()).toBe("snapshot-single-file:/var/lib/zerobyte/volumes/vol123/_data/archive");
|
||||||
|
expect(getOptionValues("--include")).toEqual(["backup.20260301-233001.7z"]);
|
||||||
|
});
|
||||||
|
|
||||||
test("does not pass an empty include when include equals restore root", async () => {
|
test("does not pass an empty include when include equals restore root", async () => {
|
||||||
const { getArgs, getRestoreArg, getOptionValues } = setup();
|
const { getArgs, getRestoreArg, getOptionValues } = setup();
|
||||||
await restore(config, "snapshot-7202d8cc", "/Users/nicolas/Documents/restore", {
|
await restore(config, "snapshot-7202d8cc", "/Users/nicolas/Documents/restore", {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ export const restore = async (
|
||||||
basePath?: string;
|
basePath?: string;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
include?: string[];
|
include?: string[];
|
||||||
|
selectedItemKind?: "file" | "dir";
|
||||||
exclude?: string[];
|
exclude?: string[];
|
||||||
excludeXattr?: string[];
|
excludeXattr?: string[];
|
||||||
delete?: boolean;
|
delete?: boolean;
|
||||||
|
|
@ -47,7 +48,11 @@ export const restore = async (
|
||||||
let restoreArg = snapshotId;
|
let restoreArg = snapshotId;
|
||||||
|
|
||||||
const includes = options.include?.length ? options.include : [options.basePath ?? "/"];
|
const includes = options.include?.length ? options.include : [options.basePath ?? "/"];
|
||||||
const commonAncestor = findCommonAncestor(includes);
|
const commonAncestor =
|
||||||
|
options.selectedItemKind === "file" && includes.length === 1
|
||||||
|
? path.posix.dirname(includes[0] ?? "/")
|
||||||
|
: findCommonAncestor(includes);
|
||||||
|
|
||||||
if (target !== "/") {
|
if (target !== "/") {
|
||||||
restoreArg = `${snapshotId}:${commonAncestor}`;
|
restoreArg = `${snapshotId}:${commonAncestor}`;
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +69,7 @@ export const restore = async (
|
||||||
args.push("--include", pattern);
|
args.push("--include", pattern);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const strippedIncludes = options.include.map((pattern) => path.relative(commonAncestor, pattern));
|
const strippedIncludes = options.include.map((pattern) => path.posix.relative(commonAncestor, pattern));
|
||||||
const includesCoverRestoreRoot = strippedIncludes.some((pattern) => pattern === "" || pattern === ".");
|
const includesCoverRestoreRoot = strippedIncludes.some((pattern) => pattern === "" || pattern === ".");
|
||||||
|
|
||||||
if (!includesCoverRestoreRoot) {
|
if (!includesCoverRestoreRoot) {
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ function getScenarioNames(runId: string): ScenarioNames {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareTestFile(runId: string): string {
|
function prepareTestFile(runId: string, fileName = "test.json"): string {
|
||||||
const runPath = path.join(testDataPath, runId);
|
const runPath = path.join(testDataPath, runId);
|
||||||
fs.mkdirSync(runPath, { recursive: true });
|
fs.mkdirSync(runPath, { recursive: true });
|
||||||
|
|
||||||
const filePath = path.join(runPath, "test.json");
|
const filePath = path.join(runPath, fileName);
|
||||||
fs.writeFileSync(filePath, JSON.stringify({ data: "test file" }));
|
fs.writeFileSync(filePath, JSON.stringify({ data: "test file" }));
|
||||||
|
|
||||||
return filePath;
|
return filePath;
|
||||||
|
|
@ -112,6 +112,55 @@ test("can backup & restore a file", async ({ page }, testInfo) => {
|
||||||
expect(JSON.parse(restoredContent)).toEqual({ data: "test file" });
|
expect(JSON.parse(restoredContent)).toEqual({ data: "test file" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("can restore a single selected file to a custom location", async ({ page }, testInfo) => {
|
||||||
|
const runId = getRunId(testInfo);
|
||||||
|
const names = getScenarioNames(runId);
|
||||||
|
const fileName = `single-file-${runId}.json`;
|
||||||
|
const filePath = prepareTestFile(runId, fileName);
|
||||||
|
const restoreTargetPath = path.join(testDataPath, fileName);
|
||||||
|
const escapedFileName = fileName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
|
|
||||||
|
fs.rmSync(restoreTargetPath, { force: true });
|
||||||
|
|
||||||
|
await gotoAndWaitForAppReady(page, "/");
|
||||||
|
await expect(page).toHaveURL("/volumes");
|
||||||
|
|
||||||
|
await createBackupScenario(page, names);
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Backup now" }).click();
|
||||||
|
await expect(page.getByText("Backup started successfully")).toBeVisible();
|
||||||
|
await expect(page.getByText("✓ Success")).toBeVisible({ timeout: 30000 });
|
||||||
|
|
||||||
|
fs.writeFileSync(filePath, JSON.stringify({ data: "modified file" }));
|
||||||
|
|
||||||
|
await page
|
||||||
|
.getByRole("button", { name: /\d+ B$/ })
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
|
await page.getByRole("link", { name: "Restore" }).click();
|
||||||
|
await expect(page).toHaveURL(/\/restore/);
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Custom location" }).click();
|
||||||
|
await page.getByRole("button", { name: "Change" }).click();
|
||||||
|
await page.getByRole("button", { name: /^test-data$/ }).click();
|
||||||
|
await expect(page.getByText("/test-data", { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
const runFolderRow = page.getByRole("button", { name: new RegExp(runId) });
|
||||||
|
await runFolderRow.locator("svg").first().click();
|
||||||
|
|
||||||
|
const fileRow = page.getByRole("button", { name: new RegExp(escapedFileName) });
|
||||||
|
await fileRow.getByRole("checkbox").click();
|
||||||
|
await expect(page.getByText("1 item selected")).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Restore 1 item" }).click();
|
||||||
|
await expect(page.getByText("Restore completed")).toBeVisible({ timeout: 30000 });
|
||||||
|
|
||||||
|
const restoredContent = fs.readFileSync(restoreTargetPath, "utf8");
|
||||||
|
expect(JSON.parse(restoredContent)).toEqual({ data: "test file" });
|
||||||
|
|
||||||
|
fs.rmSync(restoreTargetPath, { force: true });
|
||||||
|
});
|
||||||
|
|
||||||
test("deleting a volume cascades and removes its backup schedule", async ({ page }, testInfo) => {
|
test("deleting a volume cascades and removes its backup schedule", async ({ page }, testInfo) => {
|
||||||
const runId = getRunId(testInfo);
|
const runId = getRunId(testInfo);
|
||||||
const names = getScenarioNames(runId);
|
const names = getScenarioNames(runId);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue