better handle importing of existing local repository config + documentation

This commit is contained in:
Jakub Trávník 2025-12-02 12:55:35 +01:00
parent 3c7dd856df
commit 1de82fa863
2 changed files with 29 additions and 2 deletions

View file

@ -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

View file

@ -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") {