mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Merge pull request #12410 from huffman/feat/ds-backup-apis
DS backup cleanup
This commit is contained in:
commit
84761c003d
4 changed files with 57 additions and 24 deletions
|
@ -77,6 +77,8 @@ private:
|
|||
};
|
||||
|
||||
#include <quazip5/quazipfile.h>
|
||||
#include <OctreeUtils.h>
|
||||
|
||||
class EntitiesBackupHandler {
|
||||
public:
|
||||
EntitiesBackupHandler(QString entitiesFilePath, QString entitiesReplacementFilePath) :
|
||||
|
@ -111,18 +113,27 @@ public:
|
|||
qCritical() << "Failed to open models.json.gz in backup";
|
||||
return;
|
||||
}
|
||||
auto data = zipFile.readAll();
|
||||
auto rawData = zipFile.readAll();
|
||||
|
||||
zipFile.close();
|
||||
|
||||
OctreeUtils::RawOctreeData data;
|
||||
if (!OctreeUtils::readOctreeDataInfoFromData(rawData, &data)) {
|
||||
qCritical() << "Unable to parse octree data during backup recovery";
|
||||
return;
|
||||
}
|
||||
|
||||
data.resetIdAndVersion();
|
||||
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qCritical() << "Failed to unzip models.json.gz: " << zipFile.getZipError();
|
||||
return;
|
||||
}
|
||||
|
||||
QFile entitiesFile { _entitiesReplacementFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::WriteOnly)) {
|
||||
entitiesFile.write(data);
|
||||
}
|
||||
|
||||
zipFile.close();
|
||||
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qCritical() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
entitiesFile.write(data.toGzippedByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,18 +295,21 @@ void DomainContentBackupManager::removeOldBackupVersions(const BackupRule& rule)
|
|||
backupDir.entryInfoList({ AUTOMATIC_BACKUP_PREFIX + rule.extensionFormat + "*.zip" }, QDir::Files | QDir::NoSymLinks, QDir::Name);
|
||||
|
||||
int backupsToDelete = matchingFiles.length() - rule.maxBackupVersions;
|
||||
qCDebug(domain_server) << "Found" << matchingFiles.length() << "backups, deleting " << backupsToDelete << "backup(s)";
|
||||
for (int i = 0; i < backupsToDelete; ++i) {
|
||||
auto fileInfo = matchingFiles[i].absoluteFilePath();
|
||||
QFile backupFile(fileInfo);
|
||||
if (backupFile.remove()) {
|
||||
qCDebug(domain_server) << "Removed old backup: " << backupFile.fileName();
|
||||
} else {
|
||||
qCDebug(domain_server) << "Failed to remove old backup: " << backupFile.fileName();
|
||||
if (backupsToDelete <= 0) {
|
||||
qCDebug(domain_server) << "Found" << matchingFiles.length() << "backups, no backups need to be deleted";
|
||||
} else {
|
||||
qCDebug(domain_server) << "Found" << matchingFiles.length() << "backups, deleting " << backupsToDelete << "backup(s)";
|
||||
for (int i = 0; i < backupsToDelete; ++i) {
|
||||
auto fileInfo = matchingFiles[i].absoluteFilePath();
|
||||
QFile backupFile(fileInfo);
|
||||
if (backupFile.remove()) {
|
||||
qCDebug(domain_server) << "Removed old backup: " << backupFile.fileName();
|
||||
} else {
|
||||
qCDebug(domain_server) << "Failed to remove old backup: " << backupFile.fileName();
|
||||
}
|
||||
}
|
||||
qCDebug(domain_server) << "Done removing 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 << "]."
|
||||
|
@ -406,8 +409,20 @@ void DomainContentBackupManager::consolidate(QString fileName) {
|
|||
}
|
||||
}
|
||||
|
||||
void DomainContentBackupManager::createManualBackup(const QString& name) {
|
||||
createBackup(MANUAL_BACKUP_PREFIX, name);
|
||||
void DomainContentBackupManager::createManualBackup(MiniPromise::Promise promise, const QString& name) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "createManualBackup", Q_ARG(MiniPromise::Promise, promise),
|
||||
Q_ARG(const QString&, name));
|
||||
return;
|
||||
}
|
||||
|
||||
bool success;
|
||||
QString path;
|
||||
std::tie(success, path) = createBackup(MANUAL_BACKUP_PREFIX, name);
|
||||
|
||||
promise->resolve({
|
||||
{ "success", success }
|
||||
});
|
||||
}
|
||||
|
||||
std::pair<bool, QString> DomainContentBackupManager::createBackup(const QString& prefix, const QString& name) {
|
||||
|
|
|
@ -57,9 +57,8 @@ public:
|
|||
|
||||
void replaceData(QByteArray data);
|
||||
|
||||
void createManualBackup(const QString& name);
|
||||
|
||||
public slots:
|
||||
void createManualBackup(MiniPromise::Promise promise, const QString& name);
|
||||
void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||
void deleteBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||
|
||||
|
|
|
@ -2253,9 +2253,17 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
|||
return true;
|
||||
}
|
||||
|
||||
_contentManager->createManualBackup(it.value());
|
||||
auto deferred = makePromise("createManualBackup");
|
||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||
QJsonObject rootJSON;
|
||||
auto success = result["success"].toBool();
|
||||
rootJSON["success"] = success;
|
||||
QJsonDocument docJSON(rootJSON);
|
||||
connection->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(),
|
||||
JSON_MIME_TYPE.toUtf8());
|
||||
});
|
||||
_contentManager->createManualBackup(deferred, it.value());
|
||||
|
||||
connection->respond(HTTPConnection::StatusCode200);
|
||||
return true;
|
||||
|
||||
} else if (url.path() == "/domain_settings") {
|
||||
|
|
Loading…
Reference in a new issue