fix: fix db restore not applying and auto-create USB backup folder
- Reset public schema before psql restore so existing tables don't block CREATE TABLE statements (pg_dump without --clean has no DROPs) - Disconnect Prisma connection pool after restore so next request gets fresh connections against the restored data - Auto-create the USB backup subfolder if it doesn't exist instead of failing; only fail if the destination drive itself is missing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -111,19 +111,23 @@ export const startBackupCron = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const usbBackupPath = path.join(destination.path, USB_BACKUP_FOLDER_NAME);
|
||||
|
||||
if (!fs.existsSync(usbBackupPath)) {
|
||||
const errorMessage = `Folder "${USB_BACKUP_FOLDER_NAME}" not found on the drive.`;
|
||||
if (!fs.existsSync(destination.path)) {
|
||||
const errorMessage = "Backup destination drive not found or disconnected.";
|
||||
await cronJobLogStorage.completeJobLog(log.id, "failed", new Date(), errorMessage);
|
||||
await storage.createNotification(
|
||||
admin.id,
|
||||
"BACKUP",
|
||||
`❌ USB backup failed: folder "${USB_BACKUP_FOLDER_NAME}" not found on the drive. Make sure the USB drive is connected and the folder exists.`
|
||||
"❌ USB backup failed: backup drive not found. Make sure the USB drive is connected."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const usbBackupPath = path.join(destination.path, USB_BACKUP_FOLDER_NAME);
|
||||
|
||||
if (!fs.existsSync(usbBackupPath)) {
|
||||
fs.mkdirSync(usbBackupPath, { recursive: true });
|
||||
}
|
||||
|
||||
try {
|
||||
const filename = `dental_backup_usb_${Date.now()}.sql`;
|
||||
await backupDatabaseToPath({ destinationPath: usbBackupPath, filename });
|
||||
|
||||
Reference in New Issue
Block a user