From 1de82fa8633b8d53a85a94e445a7aefa8fd0de12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Tr=C3=A1vn=C3=ADk?= Date: Tue, 2 Dec 2025 12:55:35 +0100 Subject: [PATCH] better handle importing of existing local repository config + documentation --- README.md | 16 +++++++++++++++- .../modules/repositories/repositories.service.ts | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9840fbb0..dde16c55 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,21 @@ Secrets/credentials in the config file can reference environment variables using "compressionMode": "auto" } ``` - > **Note for importing existing local repositories:** If you're importing an existing repository (e.g., from a backup or migration), include the `name` field in `config` with the original subfolder name. The actual restic repo is stored at `{path}/{name}`. You can find this value in an exported config under `repositories[].config.name`. + > **Note for importing existing local repositories:** If you're migrating an existing repository (e.g., from a backup or another Zerobyte instance), include the `name` field in `config` with the original subfolder name, and set `isExistingRepository: true`. The actual restic repo is stored at `{path}/{name}`. + > + > **Example (migration):** + > ```json + > { + > "name": "my-local-repo", + > "config": { + > "backend": "local", + > "path": "/var/lib/zerobyte/repositories", + > "name": "abc123", + > "isExistingRepository": true + > } + > } + > ``` + > You can find the `config.name` value in an exported config under `repositories[].config.name`. This value must be unique across all repositories. - **S3-Compatible** ```json diff --git a/app/server/modules/repositories/repositories.service.ts b/app/server/modules/repositories/repositories.service.ts index d7dde170..03bee4cc 100644 --- a/app/server/modules/repositories/repositories.service.ts +++ b/app/server/modules/repositories/repositories.service.ts @@ -73,7 +73,20 @@ const createRepository = async (name: string, config: RepositoryConfig, compress const id = crypto.randomUUID(); - const shortId = (config.backend === "local" && config.name) ? config.name : generateShortId(); + // Determine shortId: use provided config.name for local repo migrations, otherwise generate + let shortId: string; + if (config.backend === "local" && config.name?.length) { + // User provided a name (migration scenario) - check for conflicts + shortId = config.name; + const existingByShortId = await db.query.repositoriesTable.findFirst({ + where: eq(repositoriesTable.shortId, shortId), + }); + if (existingByShortId) { + throw new ConflictError(`A repository with shortId '${shortId}' already exists. The shortId is used as the subdirectory name for local repositories.`); + } + } else { + shortId = generateShortId(); + } let processedConfig = config; if (config.backend === "local") {