// // DomainContentBackupManager.h // libraries/domain-server/src // // Created by Ryan Huffman on 1/01/18. // Adapted from OctreePersistThread // Copyright 2018 High Fidelity, Inc. // // // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #ifndef hifi_DomainContentBackupManager_h #define hifi_DomainContentBackupManager_h #include #include #include #include #include "BackupHandler.h" #include #include struct BackupItemInfo { BackupItemInfo(QString pId, QString pName, QString pAbsolutePath, QDateTime pCreatedAt, bool pIsManualBackup) : id(pId), name(pName), absolutePath(pAbsolutePath), createdAt(pCreatedAt), isManualBackup(pIsManualBackup) { }; QString id; QString name; QString absolutePath; QDateTime createdAt; bool isManualBackup; }; class DomainContentBackupManager : public GenericThread { Q_OBJECT public: class BackupRule { public: QString name; int intervalSeconds; QString extensionFormat; int maxBackupVersions; qint64 lastBackupSeconds; }; static const std::chrono::milliseconds DEFAULT_PERSIST_INTERVAL; DomainContentBackupManager(const QString& rootBackupDirectory, const QVariantList& settings, std::chrono::milliseconds persistInterval = DEFAULT_PERSIST_INTERVAL, bool debugTimestampNow = false); std::vector getAllBackups(); void addBackupHandler(BackupHandlerPointer handler); void aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist void replaceData(QByteArray data); public slots: void getAllBackupsAndStatus(MiniPromise::Promise promise); void createManualBackup(MiniPromise::Promise promise, const QString& name); void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName); void recoverFromUploadedBackup(MiniPromise::Promise promise, QByteArray uploadedBackup); void deleteBackup(MiniPromise::Promise promise, const QString& backupName); void consolidateBackup(MiniPromise::Promise promise, QString fileName); signals: void loadCompleted(); void recoveryCompleted(); protected: /// Implements generic processing behavior for this thread. virtual void setup() override; virtual bool process() override; virtual void shutdown() override; void backup(); void removeOldBackupVersions(const BackupRule& rule); void refreshBackupRules(); bool getMostRecentBackup(const QString& format, QString& mostRecentBackupFileName, QDateTime& mostRecentBackupTime); int64_t getMostRecentBackupTimeInSecs(const QString& format); void parseBackupRules(const QVariantList& backupRules); std::pair createBackup(const QString& prefix, const QString& name); bool recoverFromBackupZip(const QString& backupName, QuaZip& backupZip); private: const QString _backupDirectory; std::vector _backupHandlers; std::chrono::milliseconds _persistInterval { 0 }; std::atomic _isRecovering { false }; QString _recoveryFilename { }; std::chrono::time_point _lastCheck; std::vector _backupRules; }; #endif // hifi_DomainContentBackupManager_h