更新数据库备份逻辑
parent
9e0c416db5
commit
fe15e025aa
|
@ -256,6 +256,20 @@ const initTheme = () => {
|
|||
})
|
||||
}
|
||||
|
||||
const backupDB = (backupPath: string) => {
|
||||
const dbPath = path.join(global.lxDataPath, 'lx.data.db')
|
||||
try {
|
||||
renameSync(dbPath, backupPath)
|
||||
} catch {}
|
||||
try {
|
||||
renameSync(`${dbPath}-wal`, `${backupPath}-wal`)
|
||||
} catch {}
|
||||
try {
|
||||
renameSync(`${dbPath}-shm`, `${backupPath}-shm`)
|
||||
} catch {}
|
||||
openDirInExplorer(backupPath)
|
||||
}
|
||||
|
||||
let isInitialized = false
|
||||
export const initAppSetting = async() => {
|
||||
if (!global.lx.inited) {
|
||||
|
@ -268,14 +282,13 @@ export const initAppSetting = async() => {
|
|||
if (!isInitialized) {
|
||||
let dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
|
||||
if (dbFileExists === null) {
|
||||
const backPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
|
||||
const backupPath = path.join(global.lxDataPath, `lx.data.db.${Date.now()}.bak`)
|
||||
dialog.showMessageBoxSync({
|
||||
type: 'warning',
|
||||
message: 'Database verify failed',
|
||||
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.`,
|
||||
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.`,
|
||||
})
|
||||
renameSync(path.join(global.lxDataPath, 'lx.data.db'), backPath)
|
||||
openDirInExplorer(backPath)
|
||||
backupDB(backupPath)
|
||||
dbFileExists = await global.lx.worker.dbService.init(global.lxDataPath)
|
||||
}
|
||||
global.lx.appSetting = (await initSetting()).setting
|
||||
|
|
Loading…
Reference in New Issue