mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
feat(backups): gzip compress backups and add retention config to Instance Settings
Compress database backups with gzip (.sql.gz), reducing file size ~83%. Add backup retention configuration to Instance Settings UI with preset options (7 days, 2 weeks, 1 month). The backup scheduler now reads retention from the database on each tick so changes take effect without restart. Default retention changed from 30 to 7 days.
This commit is contained in:
parent
316790ea0a
commit
cc44d309c0
11 changed files with 107 additions and 17 deletions
|
|
@ -216,7 +216,7 @@ export function loadConfig(): Config {
|
|||
1,
|
||||
Number(process.env.PAPERCLIP_DB_BACKUP_RETENTION_DAYS) ||
|
||||
fileDatabaseBackup?.retentionDays ||
|
||||
30,
|
||||
7,
|
||||
);
|
||||
const databaseBackupDir = resolveHomeAwarePath(
|
||||
process.env.PAPERCLIP_DB_BACKUP_DIR ??
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import { setupLiveEventsWebSocketServer } from "./realtime/live-events-ws.js";
|
|||
import {
|
||||
feedbackService,
|
||||
heartbeatService,
|
||||
instanceSettingsService,
|
||||
reconcilePersistedRuntimeServicesOnStartup,
|
||||
routineService,
|
||||
} from "./services/index.js";
|
||||
|
|
@ -628,20 +629,25 @@ export async function startServer(): Promise<StartedServer> {
|
|||
|
||||
if (config.databaseBackupEnabled) {
|
||||
const backupIntervalMs = config.databaseBackupIntervalMinutes * 60 * 1000;
|
||||
const settingsSvc = instanceSettingsService(db);
|
||||
let backupInFlight = false;
|
||||
|
||||
|
||||
const runScheduledBackup = async () => {
|
||||
if (backupInFlight) {
|
||||
logger.warn("Skipping scheduled database backup because a previous backup is still running");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
backupInFlight = true;
|
||||
try {
|
||||
// Read retention from Instance Settings (DB) so changes take effect without restart
|
||||
const generalSettings = await settingsSvc.getGeneral();
|
||||
const retentionDays = generalSettings.backupRetentionDays;
|
||||
|
||||
const result = await runDatabaseBackup({
|
||||
connectionString: activeDatabaseConnectionString,
|
||||
backupDir: config.databaseBackupDir,
|
||||
retentionDays: config.databaseBackupRetentionDays,
|
||||
retentionDays,
|
||||
filenamePrefix: "paperclip",
|
||||
});
|
||||
logger.info(
|
||||
|
|
@ -650,7 +656,7 @@ export async function startServer(): Promise<StartedServer> {
|
|||
sizeBytes: result.sizeBytes,
|
||||
prunedCount: result.prunedCount,
|
||||
backupDir: config.databaseBackupDir,
|
||||
retentionDays: config.databaseBackupRetentionDays,
|
||||
retentionDays,
|
||||
},
|
||||
`Automatic database backup complete: ${formatDatabaseBackupResult(result)}`,
|
||||
);
|
||||
|
|
@ -660,7 +666,7 @@ export async function startServer(): Promise<StartedServer> {
|
|||
backupInFlight = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
logger.info(
|
||||
{
|
||||
intervalMinutes: config.databaseBackupIntervalMinutes,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import type { Db } from "@paperclipai/db";
|
|||
import { companies, instanceSettings } from "@paperclipai/db";
|
||||
import {
|
||||
DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE,
|
||||
DEFAULT_BACKUP_RETENTION_DAYS,
|
||||
instanceGeneralSettingsSchema,
|
||||
type InstanceGeneralSettings,
|
||||
instanceExperimentalSettingsSchema,
|
||||
|
|
@ -22,12 +23,14 @@ function normalizeGeneralSettings(raw: unknown): InstanceGeneralSettings {
|
|||
keyboardShortcuts: parsed.data.keyboardShortcuts ?? false,
|
||||
feedbackDataSharingPreference:
|
||||
parsed.data.feedbackDataSharingPreference ?? DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE,
|
||||
backupRetentionDays: parsed.data.backupRetentionDays ?? DEFAULT_BACKUP_RETENTION_DAYS,
|
||||
};
|
||||
}
|
||||
return {
|
||||
censorUsernameInLogs: false,
|
||||
keyboardShortcuts: false,
|
||||
feedbackDataSharingPreference: DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE,
|
||||
backupRetentionDays: DEFAULT_BACKUP_RETENTION_DAYS,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue