diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp @@ -66,7 +66,9 @@ if (!ServicesUtils::fullBackupSupport || !currentBackupID.size()) { return; } - DatabaseManager::mainConnectionManager->setLogsMonitoring(true); + bool shouldEnableLogs = DatabaseManager::isPrimaryDevice(); + DatabaseManager::mainConnectionManager->setLogsMonitoringEnabled( + shouldEnableLogs); }); return mainQueryExecutor; } @@ -75,6 +77,7 @@ std::string backupDataKey = DatabaseManager::generateBackupDataKey(); std::string backupLogDataKey = DatabaseManager::generateBackupLogDataKey(); + DatabaseManager::mainConnectionManager->setLogsMonitoringEnabled(false); DatabaseManager::mainConnectionManager->closeConnection(); std::string sqliteFilePath = DatabaseManager::mainConnectionManager->getSQLiteFilePath(); @@ -258,9 +261,6 @@ if (!ServicesUtils::fullBackupSupport) { return; } - if (!DatabaseManager::isPrimaryDevice()) { - return; - } std::string backupID = DatabaseManager::getQueryExecutor().getMetadata("backupID"); if (!backupID.size()) { @@ -428,13 +428,13 @@ "file."); // update logs to use new backup - DatabaseManager::mainConnectionManager->setLogsMonitoring(false); + DatabaseManager::mainConnectionManager->setLogsMonitoringEnabled(false); DatabaseManager::getQueryExecutor().setMetadata("backupID", backupID); DatabaseManager::getQueryExecutor().clearMetadata("logID"); if (ServicesUtils::fullBackupSupport) { DatabaseManager::setUserDataKeys( mainCompactionEncryptionKey, newLogEncryptionKey); - DatabaseManager::mainConnectionManager->setLogsMonitoring(true); + DatabaseManager::mainConnectionManager->setLogsMonitoringEnabled(true); } } diff --git a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h --- a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h +++ b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.h @@ -8,6 +8,8 @@ sqlite3_session *backupLogsSession; std::string backupDataKey; std::string backupLogDataKey; + // cache the value between connection resets + bool backupLogsEnabledOnInit; void attachSession(); void detachSession(); @@ -38,8 +40,8 @@ void setNewKeys( const std::string &backupDataKey, const std::string &backupLogDataKey); - void setLogsMonitoring(bool enabled); - bool getLogsMonitoring(); + void setLogsMonitoringEnabled(bool enabled); + bool getLogsMonitoringEnabled(); bool captureNextLog(std::string backupID, std::string logID); void restoreFromBackupLog(const std::vector &backupLog) override; diff --git a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp --- a/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp +++ b/native/cpp/CommonCpp/DatabaseManagers/NativeSQLiteConnectionManager.cpp @@ -187,17 +187,19 @@ : SQLiteConnectionManager(databasePath), backupLogsSession(nullptr), backupDataKey(backupDataKey), - backupLogDataKey(backupLogDataKey) { + backupLogDataKey(backupLogDataKey), + backupLogsEnabledOnInit(false) { } -void NativeSQLiteConnectionManager::setLogsMonitoring(bool enabled) { +void NativeSQLiteConnectionManager::setLogsMonitoringEnabled(bool enabled) { if (!backupLogsSession) { return; } sqlite3session_enable(backupLogsSession, enabled); + this->backupLogsEnabledOnInit = enabled; } -bool NativeSQLiteConnectionManager::getLogsMonitoring() { +bool NativeSQLiteConnectionManager::getLogsMonitoringEnabled() { if (!backupLogsSession) { return false; } @@ -221,7 +223,7 @@ this->dbConnection = this->createConnection(); onDatabaseOpen(getConnection()); attachSession(); - setLogsMonitoring(false); + this->setLogsMonitoringEnabled(this->backupLogsEnabledOnInit); } void NativeSQLiteConnectionManager::closeConnection() { @@ -266,10 +268,10 @@ void NativeSQLiteConnectionManager::restoreFromBackupLog( const std::vector &backupLog) { - bool initialEnabledValue = getLogsMonitoring(); - setLogsMonitoring(false); + bool initialEnabledValue = this->getLogsMonitoringEnabled(); + this->setLogsMonitoringEnabled(false); SQLiteConnectionManager::restoreFromBackupLog(backupLog); - setLogsMonitoring(initialEnabledValue); + this->setLogsMonitoringEnabled(initialEnabledValue); } void NativeSQLiteConnectionManager::setNewKeys(