mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-08 15:52:14 +02:00
Add BackupHandler for entity file backups
This commit is contained in:
parent
69298246c4
commit
e63b692d80
6 changed files with 113 additions and 7 deletions
|
@ -83,7 +83,10 @@ public:
|
|||
|
||||
void loadBackup(QuaZip& zip) {}
|
||||
|
||||
void createBackup(QuaZip& zip) const {
|
||||
// Create a skeleton backup
|
||||
void createBackup(QuaZip& zip) {
|
||||
qDebug() << "Creating a backup from handler";
|
||||
|
||||
QFile entitiesFile { _entitiesFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::ReadOnly)) {
|
||||
|
@ -97,9 +100,32 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void recoverBackup(QuaZip& zip) const {}
|
||||
void deleteBackup(QuaZip& zip) {}
|
||||
void consolidateBackup(QuaZip& zip) const {}
|
||||
// Recover from a full backup
|
||||
void recoverBackup(QuaZip& zip) {
|
||||
if (!zip.setCurrentFile("models.json.gz")) {
|
||||
qWarning() << "Failed to find models.json.gz while recovering backup";
|
||||
return;
|
||||
}
|
||||
QuaZipFile zipFile { &zip };
|
||||
zipFile.open(QIODevice::ReadOnly);
|
||||
auto data = zipFile.readAll();
|
||||
|
||||
QFile entitiesFile { _entitiesFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::WriteOnly)) {
|
||||
entitiesFile.write(data);
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
// Delete a skeleton backup
|
||||
void deleteBackup(QuaZip& zip) {
|
||||
}
|
||||
|
||||
// Create a full backup
|
||||
void consolidateBackup(QuaZip& zip) {
|
||||
}
|
||||
|
||||
private:
|
||||
QString _entitiesFilePath;
|
||||
|
|
|
@ -91,4 +91,51 @@ private:
|
|||
int _mappingRequestsInFlight { 0 };
|
||||
};
|
||||
|
||||
|
||||
#include <quazip5/quazipfile.h>
|
||||
class AssetsBackupHandler {
|
||||
public:
|
||||
AssetsBackupHandler(BackupSupervisor* backupSupervisor) : _backupSupervisor(backupSupervisor) {}
|
||||
|
||||
void loadBackup(QuaZip& zip) {}
|
||||
|
||||
void createBackup(QuaZip& zip) {
|
||||
quint64 lastRefreshTimestamp = _backupSupervisor->getLastRefreshTimestamp();
|
||||
AssetUtils::Mappings mappings = _backupSupervisor->getCurrentMappings();
|
||||
|
||||
if (lastRefreshTimestamp == 0) {
|
||||
qWarning() << "Current mappings not yet loaded, ";
|
||||
return;
|
||||
}
|
||||
|
||||
static constexpr quint64 MAX_REFRESH_TIME = 15 * 60 * 1000 * 1000;
|
||||
if (usecTimestampNow() - lastRefreshTimestamp > MAX_REFRESH_TIME) {
|
||||
qWarning() << "Backing up asset mappings that appear old.";
|
||||
}
|
||||
|
||||
QJsonObject jsonObject;
|
||||
for (const auto& mapping : mappings) {
|
||||
jsonObject.insert(mapping.first, mapping.second);
|
||||
}
|
||||
QJsonDocument document(jsonObject);
|
||||
|
||||
QuaZipFile zipFile { &zip };
|
||||
if (!zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo("mappings.json"))) {
|
||||
qDebug() << "testCreate(): outFile.open()";
|
||||
}
|
||||
zipFile.write(document.toJson());
|
||||
zipFile.close();
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qDebug() << "testCreate(): outFile.close(): " << zipFile.getZipError();
|
||||
}
|
||||
}
|
||||
|
||||
void recoverBackup(QuaZip& zip) {}
|
||||
void deleteBackup(QuaZip& zip) {}
|
||||
void consolidateBackup(QuaZip& zip) {}
|
||||
|
||||
private:
|
||||
BackupSupervisor* _backupSupervisor;
|
||||
};
|
||||
|
||||
#endif /* hifi_BackupSupervisor_h */
|
||||
|
|
|
@ -216,10 +216,35 @@ bool DomainContentBackupManager::getMostRecentBackup(const QString& format,
|
|||
return bestBackupFound;
|
||||
}
|
||||
|
||||
bool DomainContentBackupManager::recoverFromBackup(const QString& backupName) {
|
||||
qDebug() << "Recoving from" << backupName;
|
||||
|
||||
QDir backupDir { _backupDirectory };
|
||||
QFile backupFile { backupDir.filePath(backupName) };
|
||||
if (backupFile.open(QIODevice::ReadOnly)) {
|
||||
QuaZip zip { &backupFile };
|
||||
if (!zip.open(QuaZip::Mode::mdUnzip)) {
|
||||
qWarning() << "Failed to unzip file: " << backupName;
|
||||
backupFile.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& handler : _backupHandlers) {
|
||||
handler.recoverBackup(zip);
|
||||
}
|
||||
|
||||
backupFile.close();
|
||||
}
|
||||
|
||||
qDebug() << "Successfully recovered from " << backupName;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DomainContentBackupManager::removeOldBackupVersions(const BackupRule& rule) {
|
||||
QDir backupDir { _backupDirectory };
|
||||
if (backupDir.exists() && rule.maxBackupVersions > 0) {
|
||||
qCDebug(domain_server) << "Rolling old backup versions for rule" << rule.name << "...";
|
||||
qCDebug(domain_server) << "Rolling old backup versions for rule" << rule.name;
|
||||
|
||||
auto matchingFiles =
|
||||
backupDir.entryInfoList({ rule.extensionFormat + "*.zip" }, QDir::Files | QDir::NoSymLinks, QDir::Name);
|
||||
|
@ -235,11 +260,11 @@ void DomainContentBackupManager::removeOldBackupVersions(const BackupRule& rule)
|
|||
}
|
||||
}
|
||||
|
||||
qCDebug(domain_server) << "Done rolling old backup versions...";
|
||||
qCDebug(domain_server) << "Done removing old backup versions";
|
||||
} else {
|
||||
qCDebug(domain_server) << "Rolling backups for rule" << rule.name << "."
|
||||
<< " Max Rolled Backup Versions less than 1 [" << rule.maxBackupVersions << "]."
|
||||
<< " No need to roll backups...";
|
||||
<< " No need to roll backups";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,11 @@ public:
|
|||
|
||||
void replaceData(QByteArray data);
|
||||
|
||||
bool recoverFromBackup(const QString& backupName);
|
||||
|
||||
signals:
|
||||
void loadCompleted();
|
||||
|
||||
protected:
|
||||
/// Implements generic processing behavior for this thread.
|
||||
virtual void setup() override;
|
||||
|
|
|
@ -299,6 +299,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
_contentManager->addBackupHandler(new EntitiesBackupHandler(getEntitiesFilePath()));
|
||||
_contentManager->addBackupHandler(new BackupSupervisor(getContentBackupDir()));
|
||||
_contentManager->initialize(true);
|
||||
|
||||
_contentManager->recoverFromBackup("backup-daily_rolling-2018-02-06_15-13-50.zip");
|
||||
}
|
||||
|
||||
void DomainServer::parseCommandLine() {
|
||||
|
|
|
@ -2246,6 +2246,7 @@ bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElementPointer
|
|||
}
|
||||
entityDescription["DataVersion"] = _persistDataVersion;
|
||||
entityDescription["Id"] = _persistID;
|
||||
qDebug() << "Writing to map: " << _persistDataVersion << _persistID;
|
||||
QScriptEngine scriptEngine;
|
||||
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues,
|
||||
skipThoseWithBadParents, _myAvatar);
|
||||
|
|
Loading…
Reference in a new issue