Make sure the backup database process is actually created backup files. Improve https://github.com/louislam/uptime-kuma/issues/1412#issuecomment-1166576395

This commit is contained in:
Louis Lam 2022-06-28 22:11:59 +08:00
parent e36b65c2df
commit 1af6d33fcd

View File

@ -177,7 +177,13 @@ class Database {
} else {
log.info("db", "Database patch is needed");
try {
this.backup(version);
} catch (e) {
log.error("db", e);
log.error("db", "Unable to create a backup before patching the database. Please make sure you have enough space and permission.");
process.exit(1);
}
// Try catch anything here, if gone wrong, restore the backup
try {
@ -445,6 +451,23 @@ class Database {
this.backupWalPath = walPath + ".bak" + version;
fs.copyFileSync(walPath, this.backupWalPath);
}
// Double confirm if all files actually backup
if (!fs.existsSync(this.backupPath)) {
throw new Error("Backup failed! " + this.backupPath);
}
if (fs.existsSync(shmPath)) {
if (!fs.existsSync(this.backupShmPath)) {
throw new Error("Backup failed! " + this.backupShmPath);
}
}
if (fs.existsSync(walPath)) {
if (!fs.existsSync(this.backupWalPath)) {
throw new Error("Backup failed! " + this.backupWalPath);
}
}
}
}