From 99c38ced02981ded8a1a478c81544ca11166b8fc Mon Sep 17 00:00:00 2001 From: Wendy Wang Date: Mon, 20 Jan 2025 17:26:17 +0100 Subject: [PATCH] Add PRAGMA integrity_check post-copying sqlite3 db --- .../contrib/utils/database_backup/database_backup.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/evennia/contrib/utils/database_backup/database_backup.py b/evennia/contrib/utils/database_backup/database_backup.py index 8d725930b4..79e9e199fa 100644 --- a/evennia/contrib/utils/database_backup/database_backup.py +++ b/evennia/contrib/utils/database_backup/database_backup.py @@ -10,6 +10,7 @@ import datetime import os import shutil import subprocess +import sqlite3 _MUDINFO_CHANNEL = None BACKUP_FOLDER = "server/backups" @@ -62,6 +63,16 @@ class DatabaseBackupScript(DefaultScript): output_file_path += ".db3" os.makedirs(os.path.dirname(output_file_path), exist_ok=True) shutil.copy(db_name, output_file_path) + + # Check the integrity of the copied db + con = sqlite3.connect(output_file_path) + cur = con.cursor() + try: + cur.execute("PRAGMA integrity_check") + except sqlite3.DatabaseError: + self.log(f"|rsqlite3 db backup to {BACKUP_FOLDER} failed: integrity check failed|n") + con.close() + return self.log(f"|wsqlite3 db backed up in: {BACKUP_FOLDER}|n") def at_repeat(self):