mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-08 06:32:35 +02:00
Backup bug fixes
This commit is contained in:
parent
42afdd6502
commit
acc68d65c2
4 changed files with 34 additions and 58 deletions
|
@ -113,7 +113,7 @@ void AssetsBackupHandler::checkForAssetsToDelete() {
|
|||
|
||||
|
||||
std::pair<bool, float> AssetsBackupHandler::isAvailable(QString filePath) {
|
||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||
const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) {
|
||||
return value.filePath == filePath;
|
||||
});
|
||||
if (it == end(_backups)) {
|
||||
|
@ -269,7 +269,7 @@ void AssetsBackupHandler::recoverBackup(QuaZip& zip) {
|
|||
qCWarning(asset_backup) << "Current asset mappings that might be stale.";
|
||||
}
|
||||
|
||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||
const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) {
|
||||
return value.filePath == zip.getZipName();
|
||||
});
|
||||
if (it == end(_backups)) {
|
||||
|
@ -314,7 +314,7 @@ void AssetsBackupHandler::deleteBackup(const QString& absoluteFilePath) {
|
|||
return;
|
||||
}
|
||||
|
||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||
const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) {
|
||||
return value.filePath == absoluteFilePath;
|
||||
});
|
||||
if (it == end(_backups)) {
|
||||
|
@ -335,7 +335,7 @@ void AssetsBackupHandler::consolidateBackup(QuaZip& zip) {
|
|||
}
|
||||
QFileInfo zipInfo(zip.getZipName());
|
||||
|
||||
auto it = find_if(begin(_backups), end(_backups), [&](const std::vector<AssetServerBackup>::value_type& value) {
|
||||
const auto it = find_if(begin(_backups), end(_backups), [&](const AssetServerBackup& value) {
|
||||
QFileInfo info(value.filePath);
|
||||
return info.fileName() == zipInfo.fileName();
|
||||
});
|
||||
|
|
|
@ -50,7 +50,7 @@ void DomainContentBackupManager::addBackupHandler(BackupHandlerPointer handler)
|
|||
}
|
||||
|
||||
DomainContentBackupManager::DomainContentBackupManager(const QString& backupDirectory,
|
||||
const QJsonObject& settings,
|
||||
const QVariantList& backupRules,
|
||||
int persistInterval,
|
||||
bool debugTimestampNow)
|
||||
: _backupDirectory(backupDirectory),
|
||||
|
@ -62,59 +62,38 @@ DomainContentBackupManager::DomainContentBackupManager(const QString& backupDire
|
|||
// Make sure the backup directory exists.
|
||||
QDir(_backupDirectory).mkpath(".");
|
||||
|
||||
parseSettings(settings);
|
||||
parseBackupRules(backupRules);
|
||||
}
|
||||
|
||||
void DomainContentBackupManager::parseSettings(const QJsonObject& settings) {
|
||||
static const QString BACKUP_RULES_KEY = "backup_rules";
|
||||
if (settings[BACKUP_RULES_KEY].isArray()) {
|
||||
const QJsonArray& backupRules = settings[BACKUP_RULES_KEY].toArray();
|
||||
qCDebug(domain_server) << "BACKUP RULES:";
|
||||
void DomainContentBackupManager::parseBackupRules(const QVariantList& backupRules) {
|
||||
qCDebug(domain_server) << "BACKUP RULES:";
|
||||
|
||||
for (const QJsonValue& value : backupRules) {
|
||||
QJsonObject obj = value.toObject();
|
||||
for (const QVariant& value : backupRules) {
|
||||
QVariantMap map = value.toMap();
|
||||
|
||||
int interval = 0;
|
||||
int count = 0;
|
||||
int interval = map["backupInterval"].toInt();
|
||||
int count = map["maxBackupVersions"].toInt();
|
||||
auto name = map["Name"].toString();
|
||||
auto format = name.replace(" ", "_").toLower();
|
||||
|
||||
QJsonValue intervalVal = obj["backupInterval"];
|
||||
if (intervalVal.isString()) {
|
||||
interval = intervalVal.toString().toInt();
|
||||
} else {
|
||||
interval = intervalVal.toInt();
|
||||
}
|
||||
qCDebug(domain_server) << " Name:" << name;
|
||||
qCDebug(domain_server) << " format:" << format;
|
||||
qCDebug(domain_server) << " interval:" << interval;
|
||||
qCDebug(domain_server) << " count:" << count;
|
||||
|
||||
QJsonValue countVal = obj["maxBackupVersions"];
|
||||
if (countVal.isString()) {
|
||||
count = countVal.toString().toInt();
|
||||
} else {
|
||||
count = countVal.toInt();
|
||||
}
|
||||
BackupRule newRule = { name, interval, format, count, 0 };
|
||||
|
||||
auto name = obj["Name"].toString();
|
||||
auto format = name.replace(" ", "_").toLower();
|
||||
newRule.lastBackupSeconds = getMostRecentBackupTimeInSecs(format);
|
||||
|
||||
qCDebug(domain_server) << " Name:" << name;
|
||||
qCDebug(domain_server) << " format:" << format;
|
||||
qCDebug(domain_server) << " interval:" << interval;
|
||||
qCDebug(domain_server) << " count:" << count;
|
||||
|
||||
BackupRule newRule = { name, interval, format, count, 0 };
|
||||
|
||||
newRule.lastBackupSeconds = getMostRecentBackupTimeInSecs(format);
|
||||
|
||||
if (newRule.lastBackupSeconds > 0) {
|
||||
auto now = QDateTime::currentSecsSinceEpoch();
|
||||
auto sinceLastBackup = now - newRule.lastBackupSeconds;
|
||||
qCDebug(domain_server).noquote() << " lastBackup:" << formatSecTime(sinceLastBackup) << "ago";
|
||||
} else {
|
||||
qCDebug(domain_server) << " lastBackup: NEVER";
|
||||
}
|
||||
|
||||
_backupRules.push_back(newRule);
|
||||
if (newRule.lastBackupSeconds > 0) {
|
||||
auto now = QDateTime::currentSecsSinceEpoch();
|
||||
auto sinceLastBackup = now - newRule.lastBackupSeconds;
|
||||
qCDebug(domain_server).noquote() << " lastBackup:" << formatSecTime(sinceLastBackup) << "ago";
|
||||
} else {
|
||||
qCDebug(domain_server) << " lastBackup: NEVER";
|
||||
}
|
||||
} else {
|
||||
qCDebug(domain_server) << "BACKUP RULES: NONE";
|
||||
|
||||
_backupRules.push_back(newRule);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
static const int DEFAULT_PERSIST_INTERVAL;
|
||||
|
||||
DomainContentBackupManager(const QString& rootBackupDirectory,
|
||||
const QJsonObject& settings,
|
||||
const QVariantList& settings,
|
||||
int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||
bool debugTimestampNow = false);
|
||||
|
||||
|
@ -82,7 +82,7 @@ protected:
|
|||
void refreshBackupRules();
|
||||
bool getMostRecentBackup(const QString& format, QString& mostRecentBackupFileName, QDateTime& mostRecentBackupTime);
|
||||
int64_t getMostRecentBackupTimeInSecs(const QString& format);
|
||||
void parseSettings(const QJsonObject& settings);
|
||||
void parseBackupRules(const QVariantList& backupRules);
|
||||
|
||||
std::pair<bool, QString> createBackup(const QString& prefix, const QString& name);
|
||||
|
||||
|
|
|
@ -296,15 +296,12 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
qCDebug(domain_server) << "Created entities data directory";
|
||||
}
|
||||
maybeHandleReplacementEntityFile();
|
||||
|
||||
auto contentArchivesGroup = _settingsManager.valueOrDefaultValueForKeyPath(AUTOMATIC_CONTENT_ARCHIVES_GROUP);
|
||||
auto archivesIntervalObject = QJsonObject();
|
||||
|
||||
if (contentArchivesGroup.canConvert<QVariantMap>()) {
|
||||
archivesIntervalObject = QJsonObject::fromVariantMap(contentArchivesGroup.toMap());
|
||||
}
|
||||
|
||||
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), archivesIntervalObject));
|
||||
static const QString BACKUP_RULES_KEYPATH = AUTOMATIC_CONTENT_ARCHIVES_GROUP + ".backup_rules";
|
||||
auto backupRulesVariant = _settingsManager.valueOrDefaultValueForKeyPath(BACKUP_RULES_KEYPATH);
|
||||
|
||||
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), backupRulesVariant.toList()));
|
||||
|
||||
connect(_contentManager.get(), &DomainContentBackupManager::started, _contentManager.get(), [this](){
|
||||
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));
|
||||
|
|
Loading…
Reference in a new issue