mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
better error logging in backup
This commit is contained in:
parent
75bd395669
commit
e25b633ec4
@ -28,6 +28,8 @@ async function periodBackup(optionName, fileName, periodInSeconds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BACKUP_ATTEMPT_COUNT = 50;
|
||||||
|
|
||||||
async function backupNow(name) {
|
async function backupNow(name) {
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
|
|
||||||
@ -43,17 +45,19 @@ async function backupNow(name) {
|
|||||||
let success = false;
|
let success = false;
|
||||||
let attemptCount = 0
|
let attemptCount = 0
|
||||||
|
|
||||||
for (; attemptCount < 50 && !success; attemptCount++) {
|
for (; attemptCount < BACKUP_ATTEMPT_COUNT && !success; attemptCount++) {
|
||||||
try {
|
try {
|
||||||
await sql.executeNoWrap(`VACUUM INTO '${backupFile}'`);
|
await sql.executeNoWrap(`VACUUM INTO '${backupFile}'`);
|
||||||
success++;
|
success++;
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {
|
||||||
|
log.info(`Backup attempt ${attemptCount + 1} failed with "${e.message}", retrying...`);
|
||||||
|
}
|
||||||
// we re-try since VACUUM is very picky and it can't run if there's any other query currently running
|
// we re-try since VACUUM is very picky and it can't run if there's any other query currently running
|
||||||
// which is difficult to guarantee so we just re-try
|
// which is difficult to guarantee so we just re-try
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attemptCount === 10) {
|
if (attemptCount === BACKUP_ATTEMPT_COUNT) {
|
||||||
log.error(`Creating backup ${backupFile} failed`);
|
log.error(`Creating backup ${backupFile} failed`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -69,10 +73,10 @@ if (!fs.existsSync(dataDir.BACKUP_DIR)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlInit.dbReady.then(() => {
|
sqlInit.dbReady.then(() => {
|
||||||
setInterval(cls.wrap(regularBackup), 60 * 60 * 1000);
|
setInterval(cls.wrap(regularBackup), 4 * 60 * 60 * 1000);
|
||||||
|
|
||||||
// kickoff backup immediately
|
// kickoff first backup soon after start up
|
||||||
setTimeout(cls.wrap(regularBackup), 1000);
|
setTimeout(cls.wrap(regularBackup), 5 * 60 * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user