Skip to content

Commit fe15e02

Browse files
committed
更新数据库备份逻辑
1 parent 9e0c416 commit fe15e02

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/main/app.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,20 @@ const initTheme = () => {
256256
})
257257
}
258258

259+
const backupDB = (backupPath: string) => {
260+
const dbPath = path.join(global.lxDataPath, 'lx.data.db')
261+
try {
262+
renameSync(dbPath, backupPath)
263+
} catch {}
264+
try {
265+
renameSync(`${dbPath}-wal`, `${backupPath}-wal`)
266+
} catch {}
267+
try {
268+
renameSync(`${dbPath}-shm`, `${backupPath}-shm`)
269+
} catch {}
270+
openDirInExplorer(backupPath)
271+
}
272+
259273
let isInitialized = false
260274
export const initAppSetting = async() => {
261275
if (!global.lx.inited) {
@@ -268,14 +282,13 @@ export const initAppSetting = async() => {
268282
if (!isInitialized) {
269283
let dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
270284
if (dbFileExists === null) {
271-
const backPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
285+
const backupPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
272286
dialog.showMessageBoxSync({
273287
type: 'warning',
274288
message: 'Database verify failed',
275-
detail: `数据库表结构校验失败,我们将把有问题的数据库备份到:${backPath}\n若此问题导致你的数据丢失,你可以尝试从备份文件找回它们。\n\nThe database table structure verification failed, we will back up the problematic database to: ${backPath}\nIf this problem causes your data to be lost, you can try to retrieve them from the backup file.`,
289+
detail: `数据库表结构校验失败,我们将把有问题的数据库备份到:${backupPath}\n若此问题导致你的数据丢失,你可以尝试从备份文件找回它们。\n\nThe database table structure verification failed, we will back up the problematic database to: ${backupPath}\nIf this problem causes your data to be lost, you can try to retrieve them from the backup file.`,
276290
})
277-
renameSync(path.join(global.lxDataPath, 'lx.data.db'), backPath)
278-
openDirInExplorer(backPath)
291+
backupDB(backupPath)
279292
dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
280293
}
281294
global.lx.appSetting = (await initSetting()).setting

0 commit comments

Comments
 (0)