!6969 【质量加固】数据库文件丢失后,从备库恢复

Merge pull request !6969 from xuyicong/feat_restore_backupDB
This commit is contained in:
openharmony_ci 2024-09-18 06:26:14 +00:00 committed by Gitee
commit 4bd6b61aa7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -66,9 +66,14 @@ std::shared_ptr<NativeRdb::RdbStore> RdbDataManager::GetRdbStore()
isInitial_ = true;
}
// for check db exist or not
bool isNeedRebuildDb = false;
std::string rdbFilePath = bmsRdbConfig_.dbPath + std::string("/") + std::string(BMS_BACK_UP_RDB_NAME);
if (access(rdbStoreConfig.GetPath().c_str(), F_OK) != 0) {
APP_LOGW("bms db :%{public}s is not exist, need to create. errno:%{public}d",
rdbStoreConfig.GetPath().c_str(), errno);
if (access(rdbFilePath.c_str(), F_OK) == 0) {
isNeedRebuildDb = true;
}
}
int32_t errCode = NativeRdb::E_OK;
BmsRdbOpenCallback bmsRdbOpenCallback(bmsRdbConfig_);
@ -84,11 +89,10 @@ std::shared_ptr<NativeRdb::RdbStore> RdbDataManager::GetRdbStore()
CheckSystemSizeAndHisysEvent(bmsRdbConfig_.dbPath, bmsRdbConfig_.dbName);
NativeRdb::RebuiltType rebuildType = NativeRdb::RebuiltType::NONE;
int32_t rebuildCode = rdbStore_->GetRebuilt(rebuildType);
if (rebuildType == NativeRdb::RebuiltType::REBUILT) {
if (rebuildType == NativeRdb::RebuiltType::REBUILT || isNeedRebuildDb) {
APP_LOGI("start %{public}s restore ret %{public}d, type:%{public}d", bmsRdbConfig_.dbName.c_str(),
rebuildCode, static_cast<int32_t>(rebuildType));
int32_t restoreRet = rdbStore_->Restore(bmsRdbConfig_.dbPath + std::string("/") +
std::string(BMS_BACK_UP_RDB_NAME));
int32_t restoreRet = rdbStore_->Restore(rdbFilePath);
if (restoreRet != NativeRdb::E_OK) {
APP_LOGE("rdb restore failed ret:%{public}d", restoreRet);
}