mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
Fix backup loading not getting auto backups
This commit is contained in:
parent
ec3580f596
commit
0230abea79
3 changed files with 79 additions and 46 deletions
|
@ -300,12 +300,7 @@ void DomainContentBackupManager::recoverFromBackup(MiniPromise::Promise promise,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainContentBackupManager::getAllBackupInformation(MiniPromise::Promise promise) {
|
std::vector<BackupItemInfo> DomainContentBackupManager::getAllBackups() {
|
||||||
if (QThread::currentThread() != thread()) {
|
|
||||||
QMetaObject::invokeMethod(this, "getAllBackupInformation", Q_ARG(MiniPromise::Promise, promise));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir backupDir { _backupDirectory };
|
QDir backupDir { _backupDirectory };
|
||||||
auto matchingFiles =
|
auto matchingFiles =
|
||||||
backupDir.entryInfoList({ AUTOMATIC_BACKUP_PREFIX + "*.zip", MANUAL_BACKUP_PREFIX + "*.zip" },
|
backupDir.entryInfoList({ AUTOMATIC_BACKUP_PREFIX + "*.zip", MANUAL_BACKUP_PREFIX + "*.zip" },
|
||||||
|
@ -315,7 +310,7 @@ void DomainContentBackupManager::getAllBackupInformation(MiniPromise::Promise pr
|
||||||
QString dateTimeFormat = "(" + DATETIME_FORMAT_RE + ")";
|
QString dateTimeFormat = "(" + DATETIME_FORMAT_RE + ")";
|
||||||
QRegExp backupNameFormat { prefixFormat + nameFormat + "-" + dateTimeFormat + "\\.zip" };
|
QRegExp backupNameFormat { prefixFormat + nameFormat + "-" + dateTimeFormat + "\\.zip" };
|
||||||
|
|
||||||
QVariantList backups;
|
std::vector<BackupItemInfo> backups;
|
||||||
|
|
||||||
for (const auto& fileInfo : matchingFiles) {
|
for (const auto& fileInfo : matchingFiles) {
|
||||||
auto fileName = fileInfo.fileName();
|
auto fileName = fileInfo.fileName();
|
||||||
|
@ -338,17 +333,53 @@ void DomainContentBackupManager::getAllBackupInformation(MiniPromise::Promise pr
|
||||||
availabilityProgress += progress / _backupHandlers.size();
|
availabilityProgress += progress / _backupHandlers.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
backups.push_back(QVariantMap({
|
backups.push_back(
|
||||||
{ "id", fileInfo.fileName() },
|
{ fileInfo.fileName(), name, fileInfo.absoluteFilePath(), createdAt, type == MANUAL_BACKUP_PREFIX });
|
||||||
{ "name", name },
|
|
||||||
{ "createdAtMillis", createdAt.toMSecsSinceEpoch() },
|
|
||||||
{ "isAvailable", isAvailable },
|
|
||||||
{ "availabilityProgress", availabilityProgress },
|
|
||||||
{ "isManualBackup", type == MANUAL_BACKUP_PREFIX }
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return backups;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DomainContentBackupManager::getAllBackupsAndStatus(MiniPromise::Promise promise) {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "getAllBackupInformation", Q_ARG(MiniPromise::Promise, promise));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir backupDir { _backupDirectory };
|
||||||
|
auto matchingFiles =
|
||||||
|
backupDir.entryInfoList({ AUTOMATIC_BACKUP_PREFIX + "*.zip", MANUAL_BACKUP_PREFIX + "*.zip" },
|
||||||
|
QDir::Files | QDir::NoSymLinks, QDir::Name);
|
||||||
|
QString prefixFormat = "(" + QRegExp::escape(AUTOMATIC_BACKUP_PREFIX) + "|" + QRegExp::escape(MANUAL_BACKUP_PREFIX) + ")";
|
||||||
|
QString nameFormat = "(.+)";
|
||||||
|
QString dateTimeFormat = "(" + DATETIME_FORMAT_RE + ")";
|
||||||
|
QRegExp backupNameFormat { prefixFormat + nameFormat + "-" + dateTimeFormat + "\\.zip" };
|
||||||
|
|
||||||
|
auto backups = getAllBackups();
|
||||||
|
|
||||||
|
QVariantList variantBackups;
|
||||||
|
|
||||||
|
for (auto& backup : backups) {
|
||||||
|
bool isAvailable { true };
|
||||||
|
float availabilityProgress { 0.0f };
|
||||||
|
for (auto& handler : _backupHandlers) {
|
||||||
|
bool handlerIsAvailable { true };
|
||||||
|
float progress { 0.0f };
|
||||||
|
std::tie(handlerIsAvailable, progress) = handler->isAvailable(backup.absolutePath);
|
||||||
|
isAvailable &= handlerIsAvailable;
|
||||||
|
availabilityProgress += progress / _backupHandlers.size();
|
||||||
|
}
|
||||||
|
variantBackups.push_back(QVariantMap({
|
||||||
|
{ "id", backup.id },
|
||||||
|
{ "name", backup.name },
|
||||||
|
{ "createdAtMillis", backup.createdAt.toMSecsSinceEpoch() },
|
||||||
|
{ "isAvailable", isAvailable },
|
||||||
|
{ "availabilityProgress", availabilityProgress },
|
||||||
|
{ "isManualBackup", backup.isManualBackup }
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
float recoveryProgress = 0.0f;
|
float recoveryProgress = 0.0f;
|
||||||
bool isRecovering = _isRecovering.load();
|
bool isRecovering = _isRecovering.load();
|
||||||
if (_isRecovering) {
|
if (_isRecovering) {
|
||||||
|
@ -365,7 +396,7 @@ void DomainContentBackupManager::getAllBackupInformation(MiniPromise::Promise pr
|
||||||
};
|
};
|
||||||
|
|
||||||
QVariantMap info {
|
QVariantMap info {
|
||||||
{ "backups", backups },
|
{ "backups", variantBackups },
|
||||||
{ "status", status }
|
{ "status", status }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -404,32 +435,27 @@ void DomainContentBackupManager::removeOldBackupVersions(const BackupRule& rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
void DomainContentBackupManager::load() {
|
void DomainContentBackupManager::load() {
|
||||||
QDir backupDir { _backupDirectory };
|
auto backups = getAllBackups();
|
||||||
if (backupDir.exists()) {
|
for (auto& backup : backups) {
|
||||||
|
QFile backupFile{ backup.absolutePath };
|
||||||
auto matchingFiles = backupDir.entryInfoList({ "backup-*.zip" }, QDir::Files | QDir::NoSymLinks, QDir::Name);
|
if (!backupFile.open(QIODevice::ReadOnly)) {
|
||||||
|
qCritical() << "Could not open file:" << backup.absolutePath;
|
||||||
for (const auto& file : matchingFiles) {
|
qCritical() << " ERROR:" << backupFile.errorString();
|
||||||
QFile backupFile { file.absoluteFilePath() };
|
continue;
|
||||||
if (!backupFile.open(QIODevice::ReadOnly)) {
|
|
||||||
qCritical() << "Could not open file:" << file.absoluteFilePath();
|
|
||||||
qCritical() << " ERROR:" << backupFile.errorString();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QuaZip zip { &backupFile };
|
|
||||||
if (!zip.open(QuaZip::mdUnzip)) {
|
|
||||||
qCritical() << "Could not open backup archive:" << file.absoluteFilePath();
|
|
||||||
qCritical() << " ERROR:" << zip.getZipError();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& handler : _backupHandlers) {
|
|
||||||
handler->loadBackup(zip);
|
|
||||||
}
|
|
||||||
|
|
||||||
zip.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QuaZip zip{ &backupFile };
|
||||||
|
if (!zip.open(QuaZip::mdUnzip)) {
|
||||||
|
qCritical() << "Could not open backup archive:" << backup.absolutePath;
|
||||||
|
qCritical() << " ERROR:" << zip.getZipError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& handler : _backupHandlers) {
|
||||||
|
handler->loadBackup(zip);
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,14 @@
|
||||||
|
|
||||||
#include <shared/MiniPromises.h>
|
#include <shared/MiniPromises.h>
|
||||||
|
|
||||||
|
struct BackupItemInfo {
|
||||||
|
QString id;
|
||||||
|
QString name;
|
||||||
|
QString absolutePath;
|
||||||
|
QDateTime createdAt;
|
||||||
|
bool isManualBackup;
|
||||||
|
};
|
||||||
|
|
||||||
class DomainContentBackupManager : public GenericThread {
|
class DomainContentBackupManager : public GenericThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -43,14 +51,13 @@ public:
|
||||||
int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||||
bool debugTimestampNow = false);
|
bool debugTimestampNow = false);
|
||||||
|
|
||||||
|
std::vector<BackupItemInfo> getAllBackups();
|
||||||
void addBackupHandler(BackupHandlerPointer handler);
|
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 aboutToFinish(); /// call this to inform the persist thread that the owner is about to finish to support final persist
|
||||||
|
|
||||||
void replaceData(QByteArray data);
|
void replaceData(QByteArray data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void getAllBackupInformation(MiniPromise::Promise promise);
|
void getAllBackupsAndStatus(MiniPromise::Promise promise);
|
||||||
void createManualBackup(MiniPromise::Promise promise, const QString& name);
|
void createManualBackup(MiniPromise::Promise promise, const QString& name);
|
||||||
void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName);
|
void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||||
void deleteBackup(MiniPromise::Promise promise, const QString& backupName);
|
void deleteBackup(MiniPromise::Promise promise, const QString& backupName);
|
||||||
|
|
|
@ -2128,13 +2128,13 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (url.path() == URI_API_BACKUPS) {
|
} else if (url.path() == URI_API_BACKUPS) {
|
||||||
auto deferred = makePromise("getAllBackupInformation");
|
auto deferred = makePromise("getAllBackupsAndStatus");
|
||||||
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
deferred->then([connection, JSON_MIME_TYPE](QString error, QVariantMap result) {
|
||||||
QJsonDocument docJSON(QJsonObject::fromVariantMap(result));
|
QJsonDocument docJSON(QJsonObject::fromVariantMap(result));
|
||||||
|
|
||||||
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
connection->respond(HTTPConnection::StatusCode200, docJSON.toJson(), JSON_MIME_TYPE.toUtf8());
|
||||||
});
|
});
|
||||||
_contentManager->getAllBackupInformation(deferred);
|
_contentManager->getAllBackupsAndStatus(deferred);
|
||||||
return true;
|
return true;
|
||||||
} else if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
} else if (url.path().startsWith(URI_API_BACKUPS_ID)) {
|
||||||
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
auto id = url.path().mid(QString(URI_API_BACKUPS_ID).length());
|
||||||
|
|
Loading…
Reference in a new issue