feat(installer): add config backup utility for safe upgrades
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs"
|
||||||
|
import { dirname } from "node:path"
|
||||||
|
|
||||||
|
export interface BackupResult {
|
||||||
|
success: boolean
|
||||||
|
backupPath?: string
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function backupConfigFile(configPath: string): BackupResult {
|
||||||
|
if (!existsSync(configPath)) {
|
||||||
|
return { success: true }
|
||||||
|
}
|
||||||
|
|
||||||
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
|
||||||
|
const backupPath = `${configPath}.backup-${timestamp}`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dir = dirname(backupPath)
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
mkdirSync(dir, { recursive: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
copyFileSync(configPath, backupPath)
|
||||||
|
return { success: true, backupPath }
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: err instanceof Error ? err.message : "Failed to create backup",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user