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
This commit is contained in:
Nico 2025-12-18 22:34:21 +01:00 committed by GitHub
parent fd5193b5e3
commit 6a86de7b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -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"];

View file

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