From 6a86de7b95825e6aabf820e33d1eb29e3830fd25 Mon Sep 17 00:00:00 2001 From: Nico <47644445+nicotsx@users.noreply.github.com> Date: Thu, 18 Dec 2025 22:34:21 +0100 Subject: [PATCH] refactor: add default excludes to backups (#178) - To avoid accidentaly backing up a repository to itself - To avoid accidentaly backing up zerobyte's internal data --- app/server/core/constants.ts | 6 ++++++ app/server/utils/restic.ts | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/server/core/constants.ts b/app/server/core/constants.ts index efc2b8c9..2f876968 100644 --- a/app/server/core/constants.ts +++ b/app/server/core/constants.ts @@ -4,4 +4,10 @@ export const REPOSITORY_BASE = "/var/lib/zerobyte/repositories"; export const DATABASE_URL = "/var/lib/zerobyte/data/ironmount.db"; export const RESTIC_PASS_FILE = "/var/lib/zerobyte/data/restic.pass"; +export const DEFAULT_EXCLUDES = [ + DATABASE_URL, + RESTIC_PASS_FILE, + "/var/lib/zerobyte/repositories/**", // To avoid circular backups +]; + export const REQUIRED_MIGRATIONS = ["v0.14.0"]; diff --git a/app/server/utils/restic.ts b/app/server/utils/restic.ts index 207bec99..ebd52e23 100644 --- a/app/server/utils/restic.ts +++ b/app/server/utils/restic.ts @@ -5,7 +5,7 @@ import os from "node:os"; import { throttle } from "es-toolkit"; import { type } from "arktype"; import { $ } from "bun"; -import { REPOSITORY_BASE, RESTIC_PASS_FILE } from "../core/constants"; +import { REPOSITORY_BASE, RESTIC_PASS_FILE, DEFAULT_EXCLUDES } from "../core/constants"; import { logger } from "./logger"; import { cryptoUtils } from "./crypto"; import type { RetentionPolicy } from "../modules/backups/backups.dto"; @@ -275,6 +275,10 @@ const backup = async ( args.push(source); } + for (const exclude of DEFAULT_EXCLUDES) { + args.push("--exclude", exclude); + } + if (options?.exclude && options.exclude.length > 0) { for (const pattern of options.exclude) { args.push("--exclude", pattern);