mirror of
https://github.com/overte-org/overte.git
synced 2025-06-30 21:19:34 +02:00
Add consolidate
This commit is contained in:
parent
272f95efa2
commit
c41ad1a699
4 changed files with 72 additions and 5 deletions
|
@ -104,7 +104,7 @@ void BackupSupervisor::checkForAssetsToDelete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::loadBackup(QuaZip& zip) {
|
void BackupSupervisor::loadBackup(QuaZip& zip) {
|
||||||
_backups.push_back({ zip.getZipName().toStdString(), {}, false });
|
_backups.push_back({ zip.getZipName(), {}, false });
|
||||||
auto& backup = _backups.back();
|
auto& backup = _backups.back();
|
||||||
|
|
||||||
if (!zip.setCurrentFile(MAPPINGS_FILE)) {
|
if (!zip.setCurrentFile(MAPPINGS_FILE)) {
|
||||||
|
@ -171,7 +171,7 @@ void BackupSupervisor::createBackup(QuaZip& zip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetServerBackup backup;
|
AssetServerBackup backup;
|
||||||
backup.filePath = zip.getZipName().toStdString();
|
backup.filePath = zip.getZipName();
|
||||||
|
|
||||||
QJsonObject jsonObject;
|
QJsonObject jsonObject;
|
||||||
for (const auto& mapping : _currentMappings) {
|
for (const auto& mapping : _currentMappings) {
|
||||||
|
@ -214,7 +214,7 @@ void BackupSupervisor::recoverBackup(QuaZip& zip) {
|
||||||
startOperation();
|
startOperation();
|
||||||
|
|
||||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||||
return value.filePath == zip.getZipName().toStdString();
|
return value.filePath == zip.getZipName();
|
||||||
});
|
});
|
||||||
if (it == end(_backups)) {
|
if (it == end(_backups)) {
|
||||||
qCDebug(backup_supervisor) << "Could not find backup";
|
qCDebug(backup_supervisor) << "Could not find backup";
|
||||||
|
@ -235,7 +235,7 @@ void BackupSupervisor::deleteBackup(QuaZip& zip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||||
return value.filePath == zip.getZipName().toStdString();
|
return value.filePath == zip.getZipName();
|
||||||
});
|
});
|
||||||
if (it == end(_backups)) {
|
if (it == end(_backups)) {
|
||||||
qCDebug(backup_supervisor) << "Could not find backup";
|
qCDebug(backup_supervisor) << "Could not find backup";
|
||||||
|
@ -247,6 +247,44 @@ void BackupSupervisor::deleteBackup(QuaZip& zip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupSupervisor::consolidateBackup(QuaZip& zip) {
|
void BackupSupervisor::consolidateBackup(QuaZip& zip) {
|
||||||
|
if (operationInProgress()) {
|
||||||
|
qCWarning(backup_supervisor) << "There is a backup/restore in progress.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QFileInfo zipInfo(zip.getZipName());
|
||||||
|
|
||||||
|
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||||
|
QFileInfo info(value.filePath);
|
||||||
|
return info.fileName() == zipInfo.fileName();
|
||||||
|
});
|
||||||
|
if (it == end(_backups)) {
|
||||||
|
qCDebug(backup_supervisor) << "Could not find backup" << zip.getZipName();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& mapping : it->mappings) {
|
||||||
|
const auto& hash = mapping.second;
|
||||||
|
|
||||||
|
QDir assetsDir { _assetsDirectory };
|
||||||
|
QFile file { assetsDir.filePath(hash) };
|
||||||
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
|
qCCritical(backup_supervisor) << "Could not open asset file" << file.fileName();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZipFile zipFile { &zip };
|
||||||
|
static const QString ZIP_ASSETS_FOLDER = "files/";
|
||||||
|
if (!zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(ZIP_ASSETS_FOLDER + hash))) {
|
||||||
|
qCDebug(backup_supervisor) << "testCreate(): outFile.open()";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
zipFile.write(file.readAll());
|
||||||
|
zipFile.close();
|
||||||
|
if (zipFile.getZipError() != UNZ_OK) {
|
||||||
|
qCDebug(backup_supervisor) << "testCreate(): outFile.close(): " << zipFile.getZipError();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
class QuaZip;
|
class QuaZip;
|
||||||
|
|
||||||
struct AssetServerBackup {
|
struct AssetServerBackup {
|
||||||
std::string filePath;
|
QString filePath;
|
||||||
AssetUtils::Mappings mappings;
|
AssetUtils::Mappings mappings;
|
||||||
bool corruptedBackup;
|
bool corruptedBackup;
|
||||||
};
|
};
|
||||||
|
|
|
@ -308,3 +308,31 @@ void DomainContentBackupManager::backup() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainContentBackupManager::consolidate(QString fileName) {
|
||||||
|
QDir backupDir { _backupDirectory };
|
||||||
|
if (backupDir.exists()) {
|
||||||
|
auto filePath = backupDir.absoluteFilePath(fileName);
|
||||||
|
|
||||||
|
auto copyFilePath = QDir::tempPath() + "/" + fileName;
|
||||||
|
|
||||||
|
auto copySuccess = QFile::copy(filePath, copyFilePath);
|
||||||
|
if (!copySuccess) {
|
||||||
|
qCritical() << "Failed to create full backup.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZip zip(copyFilePath);
|
||||||
|
if (!zip.open(QuaZip::mdAdd)) {
|
||||||
|
qCritical() << "Could not open backup archive:" << filePath;
|
||||||
|
qCritical() << " ERROR:" << zip.getZipError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& handler : _backupHandlers) {
|
||||||
|
handler.consolidateBackup(zip);
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ protected:
|
||||||
void persist();
|
void persist();
|
||||||
void load();
|
void load();
|
||||||
void backup();
|
void backup();
|
||||||
|
void consolidate(QString fileName);
|
||||||
void removeOldBackupVersions(const BackupRule& rule);
|
void removeOldBackupVersions(const BackupRule& rule);
|
||||||
bool getMostRecentBackup(const QString& format, QString& mostRecentBackupFileName, QDateTime& mostRecentBackupTime);
|
bool getMostRecentBackup(const QString& format, QString& mostRecentBackupFileName, QDateTime& mostRecentBackupTime);
|
||||||
int64_t getMostRecentBackupTimeInSecs(const QString& format);
|
int64_t getMostRecentBackupTimeInSecs(const QString& format);
|
||||||
|
|
Loading…
Reference in a new issue