1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DISTRIBUTEDDATAMGR_BACKUP_HANDLER_H 17 #define DISTRIBUTEDDATAMGR_BACKUP_HANDLER_H 18 19 #include "kv_store_nb_delegate.h" 20 #include "kv_store_delegate.h" 21 #include "types.h" 22 #include "kv_scheduler.h" 23 #include "kvstore_meta_manager.h" 24 #include "ikvstore_data_service.h" 25 #include "kvstore_app_manager.h" 26 27 namespace OHOS::DistributedKv { 28 class BackupHandler { 29 public: 30 explicit BackupHandler(IKvStoreDataService *kvStoreDataService); 31 BackupHandler(); 32 ~BackupHandler(); 33 void BackSchedule(); 34 void SingleKvStoreBackup(const MetaData &metaData); 35 void MultiKvStoreBackup(const MetaData &metaData); 36 bool SingleKvStoreRecover(MetaData &metaData, DistributedDB::KvStoreNbDelegate *delegate); 37 bool MultiKvStoreRecover(MetaData &metaData, DistributedDB::KvStoreDelegate *delegate); 38 39 static const std::string &GetBackupPath(const std::string &deviceAccountId, int pathType); 40 static bool RenameFile(const std::string &oldPath, const std::string &newPath); 41 static bool RemoveFile(const std::string &path); 42 static bool FileExists(const std::string &path); 43 static std::string GetHashedBackupName(const std::string &bundleName); 44 45 struct BackupPara { 46 KvStoreAppManager::PathType pathType; 47 DistributedDB::CipherPassword password; 48 std::string backupFullName; 49 std::string backupBackFullName; 50 }; 51 private: 52 bool CheckNeedBackup(); 53 bool InitBackupPara(const MetaData &metaData, BackupPara &backupPara); 54 55 static std::string backupDirCe_; 56 static std::string backupDirDe_; 57 58 KvScheduler scheduler_ {}; 59 int64_t backupSuccessTime_ = 0; 60 }; 61 } // namespace OHOS::DistributedKv 62 #endif // DISTRIBUTEDDATAMGR_BACKUP_HANDLER_H 63