Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions apps/dokploy/__test__/backups/web-server-filters.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { execSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { WEB_SERVER_BACKUP_EXCLUDES } from "@dokploy/server/utils/backups/web-server-filters";
import { afterEach, describe, expect, it } from "vitest";

const hasRsync = (() => {
try {
execSync("rsync --version", { stdio: "ignore" });
return true;
} catch {
return false;
}
})();

let root: string | undefined;
afterEach(() => {
if (root) rmSync(root, { recursive: true, force: true });
root = undefined;
});

const backedUpFiles = (files: string[]) => {
root = mkdtempSync(join(tmpdir(), "web-server-filters-"));
const src = join(root, "src");
const dst = join(root, "dst");
mkdirSync(dst);
for (const file of files) {
mkdirSync(dirname(join(src, file)), { recursive: true });
writeFileSync(join(src, file), "x");
}
execSync(`rsync -a ${WEB_SERVER_BACKUP_EXCLUDES.join(" ")} ${src}/ ${dst}/`);
return execSync("find . -type f", { cwd: dst })
.toString()
.trim()
.split("\n")
.map((file) => file.replace(/^\.\//, ""))
.sort();
};

describe("WEB_SERVER_BACKUP_EXCLUDES", () => {
it.skipIf(!hasRsync)(
"skips cloned .git history but keeps working trees and bind-mounted data",
() => {
const files = backedUpFiles([
"applications/git-app/code/.git/HEAD",
"applications/git-app/code/.git/objects/pack/big.pack",
"applications/git-app/code/src/index.ts",
"applications/drop-app/code/index.html",
"compose/stack/code/.git/HEAD",
"compose/stack/code/docker-compose.yml",
"compose/stack/code/data/PG_VERSION",
"compose/stack/files/config.yml",
"traefik/traefik.yml",
]);

expect(files).toEqual([
"applications/drop-app/code/index.html",
"applications/git-app/code/src/index.ts",
"compose/stack/code/data/PG_VERSION",
"compose/stack/code/docker-compose.yml",
"compose/stack/files/config.yml",
"traefik/traefik.yml",
]);
},
);
});
7 changes: 7 additions & 0 deletions packages/server/src/utils/backups/web-server-filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// rsync excludes for the web-server backup. Every deploy re-clones */code/,
// so its .git history is never needed. The working tree stays in the backup:
// compose bind mounts like ./data live there, and restore replaces BASE_PATH.
export const WEB_SERVER_BACKUP_EXCLUDES = [
"--exclude='applications/*/code/.git/'",
"--exclude='compose/*/code/.git/'",
];
3 changes: 2 additions & 1 deletion packages/server/src/utils/backups/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { sendDokployBackupNotifications } from "../notifications/dokploy-backup"
import { execAsync } from "../process/execAsync";
import { redactRcloneCredentials } from "./redact";
import { getBackupFileName, getS3Credentials, normalizeS3Path } from "./utils";
import { WEB_SERVER_BACKUP_EXCLUDES } from "./web-server-filters";

function formatBytes(bytes?: number) {
if (bytes === undefined) return "Unknown size";
Expand Down Expand Up @@ -85,7 +86,7 @@ export const runWebServerBackup = async (backup: BackupSchedule) => {
await execAsync(cleanupCommand);

await execAsync(
`rsync -a --ignore-errors --no-specials --no-devices --exclude='volume-backups/' --exclude='${ENCRYPTION_KEY_BACKUP_FILE}' ${BASE_PATH}/ ${tempDir}/filesystem/`,
`rsync -a --ignore-errors --no-specials --no-devices --exclude='volume-backups/' --exclude='${ENCRYPTION_KEY_BACKUP_FILE}' ${WEB_SERVER_BACKUP_EXCLUDES.join(" ")} ${BASE_PATH}/ ${tempDir}/filesystem/`,
);

writeStream.write("Copied filesystem to temp directory\n");
Expand Down
Loading