Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve progress during lengthy backup work (#6939)

[._.]/ Adam Eivy2c53750b24fd
diff --git a/server/services/backup.js b/server/services/backup.js
index 2518dc4534..f3ad7f2c06 100644
--- a/server/services/backup.js
+++ b/server/services/backup.js
@@ -307,7 +307,10 @@ export function resolveRsyncBinary(env = process.env) {
function runRsync(srcDir, destDir, flags = []) {
return new Promise((resolve, reject) => {
- const args = ['--archive', '--itemize-changes', ...flags, srcDir + '/', destDir];
+ // `--itemize-changes` emits only after each file finishes. `--progress` is
+ // also supported by macOS's bundled rsync 2.6.9 and emits within a large
+ // file, giving the idle watchdog evidence that a slow transfer is healthy.
+ const args = ['--archive', '--itemize-changes', '--progress', ...flags, srcDir + '/', destDir];
const proc = spawn(resolveRsyncBinary(), args, { shell: false });
const changed = [];
@@ -822,12 +825,12 @@ export async function restoreSnapshot(destPath, snapshotId, { dryRun = true, sub
try {
changedFiles = await runRsync(srcDir, PATHS.data, flags);
} catch (err) {
- if (!dryRun && err?.code === 'BACKUP_PROCESS_TIMEOUT') {
+ if (!dryRun) {
const partialRestoreError = new Error(
`${err.message}. Some files may already have been overwritten because file restore is not transactional.`,
{ cause: err },
);
- partialRestoreError.code = err.code;
+ if (err?.code) partialRestoreError.code = err.code;
throw partialRestoreError;
}
throw err;
@@ -917,14 +920,16 @@ export async function restorePostgres(destPath, snapshotId, { dryRun = true } =
const proc = spawn('psql', [
'-v', 'ON_ERROR_STOP=1',
'--single-transaction',
+ '--echo-all',
'-h', pgHost, '-p', pgPort, '-U', pgUser, '-d', pgDb, '-f', sqlPath
], { shell: false, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, PGPASSWORD: process.env.PGPASSWORD || 'portos' } });
let stderr = '';
const watchdog = watchBackupProcess(proc, { label: 'PostgreSQL restore' });
- // psql's output is never retained, but it must be drained: unread piped
- // output can backpressure and deadlock a verbose restore. Each chunk is also
- // the supported progress signal that keeps an active long restore alive.
+ // `--echo-all` echoes input as psql consumes it, including rows within a
+ // long COPY. The output is never retained, but it must be drained: unread
+ // piped output can backpressure and deadlock a verbose restore. Each chunk
+ // is also the progress signal that keeps an active long restore alive.
proc.stdout.on('data', watchdog.markActivity);
proc.stderr.on('data', (chunk) => {
watchdog.markActivity();
diff --git a/server/services/backup.test.js b/server/services/backup.test.js
index 5711d7234f..3d52ce373a 100644
--- a/server/services/backup.test.js
+++ b/server/services/backup.test.js
@@ -803,7 +803,7 @@ describe('restorePostgres', () => {
expect(result).toEqual({ status: 'ok', dryRun: false, sizeBytes: 4096, tableCount: 1 });
const [bin, args, opts] = spawn.mock.calls[0];
expect(bin).toBe('psql');
- expect(args).toEqual(expect.arrayContaining(['-v', 'ON_ERROR_STOP=1', '--single-transaction', '-f']));
+ expect(args).toEqual(expect.arrayContaining(['-v', 'ON_ERROR_STOP=1', '--single-transaction', '--echo-all', '-f']));
expect(opts.shell).toBe(false);
expect(opts.stdio).toEqual(['ignore', 'pipe', 'pipe']);
expect(child.stdin).toBeNull();
@@ -1174,7 +1174,7 @@ describe('restoreSnapshot subdirFilter guard', () => {
});
expect(spawn).toHaveBeenCalledWith(
'/custom/bin/rsync',
- expect.arrayContaining(['--archive', '--itemize-changes', '--dry-run']),
+ expect.arrayContaining(['--archive', '--itemize-changes', '--progress', '--dry-run']),
{ shell: false },
);
} finally {
@@ -1462,6 +1462,7 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>
expect(spawn.mock.calls[0][1]).toEqual([
'--archive',
'--itemize-changes',
+ '--progress',
'--itemize-changes',
'--dry-run',
'--include=brain/***',
@@ -1529,7 +1530,7 @@ describe('restoreSnapshot snapshotId, filter flags, and settings re-sync', () =>
proc.stderr.emit('data', Buffer.from('boom'));
proc.emit('close', 1);
- await expect(pending).rejects.toThrow(/rsync exited with code 1/);
+ await expect(pending).rejects.toThrow(/rsync exited with code 1.*files may already have been overwritten/i);
expect(reloadSettings).not.toHaveBeenCalled();
});
});
@@ -1650,7 +1651,7 @@ describe('runBackup lifecycle', () => {
const [bin, args, opts] = spawn.mock.calls[0];
expect(bin).toBe('rsync');
expect(opts).toEqual({ shell: false });
- expect(args.slice(0, 2)).toEqual(['--archive', '--itemize-changes']);
+ expect(args.slice(0, 3)).toEqual(['--archive', '--itemize-changes', '--progress']);
// Source is PATHS.data with a trailing slash (copy contents, not the dir);
// destination is the snapshot's data/ subdir.
expect(args.at(-2)).toBe(`${dataRoot}/`);