Fix: Close existing SQL connections before backup to prevent abnormal termination
- Added explicit connection cleanup in createDatabaseBackup() - Resolves 'BACKUP DATABASE is terminating abnormally' error in runBackupProcess() - Prevents connection pool conflicts when running scheduled backups
This commit is contained in:
10
index.js
10
index.js
@@ -144,13 +144,21 @@ async function getDbSizeBytes() {
|
||||
async function createDatabaseBackup() {
|
||||
try {
|
||||
console.log('Connecting to database...');
|
||||
|
||||
// Close any existing connection to avoid conflicts
|
||||
try {
|
||||
await sql.close();
|
||||
} catch (closeErr) {
|
||||
// Ignore error if no connection exists
|
||||
}
|
||||
|
||||
await sql.connect(config);
|
||||
|
||||
console.log('Creating database backup...');
|
||||
const backupQuery = `
|
||||
BACKUP DATABASE [${process.env.MSSQL_DATABASE}]
|
||||
TO DISK = N'${backupFilePath}'
|
||||
WITH FORMAT, INIT, NAME = N'${process.env.MSSQL_DATABASE}-Vollständig Datenbank Sichern',
|
||||
WITH FORMAT, INIT, COMPRESSION, NAME = N'${process.env.MSSQL_DATABASE}-Vollständig Datenbank Sichern',
|
||||
SKIP, NOREWIND, NOUNLOAD, STATS = 10
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user