Backup bug fixes

This commit is contained in:
Atlante45 2018-02-16 13:53:55 -08:00
parent 42afdd6502
commit acc68d65c2
4 changed files with 34 additions and 58 deletions

View file

@ -113,7 +113,7 @@ void AssetsBackupHandler::checkForAssetsToDelete() {
std::pair<bool, float> AssetsBackupHandler::isAvailable(QString filePath) { 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; return value.filePath == filePath;
}); });
if (it == end(_backups)) { if (it == end(_backups)) {
@ -269,7 +269,7 @@ void AssetsBackupHandler::recoverBackup(QuaZip& zip) {
qCWarning(asset_backup) << "Current asset mappings that might be stale."; 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(); return value.filePath == zip.getZipName();
}); });
if (it == end(_backups)) { if (it == end(_backups)) {
@ -314,7 +314,7 @@ void AssetsBackupHandler::deleteBackup(const QString& absoluteFilePath) {
return; 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; return value.filePath == absoluteFilePath;
}); });
if (it == end(_backups)) { if (it == end(_backups)) {
@ -335,7 +335,7 @@ void AssetsBackupHandler::consolidateBackup(QuaZip& zip) {
} }
QFileInfo zipInfo(zip.getZipName()); 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); QFileInfo info(value.filePath);
return info.fileName() == zipInfo.fileName(); return info.fileName() == zipInfo.fileName();
}); });

View file

@ -50,7 +50,7 @@ void DomainContentBackupManager::addBackupHandler(BackupHandlerPointer handler)
} }
DomainContentBackupManager::DomainContentBackupManager(const QString& backupDirectory, DomainContentBackupManager::DomainContentBackupManager(const QString& backupDirectory,
const QJsonObject& settings, const QVariantList& backupRules,
int persistInterval, int persistInterval,
bool debugTimestampNow) bool debugTimestampNow)
: _backupDirectory(backupDirectory), : _backupDirectory(backupDirectory),
@ -62,36 +62,18 @@ DomainContentBackupManager::DomainContentBackupManager(const QString& backupDire
// Make sure the backup directory exists. // Make sure the backup directory exists.
QDir(_backupDirectory).mkpath("."); QDir(_backupDirectory).mkpath(".");
parseSettings(settings); parseBackupRules(backupRules);
} }
void DomainContentBackupManager::parseSettings(const QJsonObject& settings) { void DomainContentBackupManager::parseBackupRules(const QVariantList& backupRules) {
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:"; qCDebug(domain_server) << "BACKUP RULES:";
for (const QJsonValue& value : backupRules) { for (const QVariant& value : backupRules) {
QJsonObject obj = value.toObject(); QVariantMap map = value.toMap();
int interval = 0; int interval = map["backupInterval"].toInt();
int count = 0; int count = map["maxBackupVersions"].toInt();
auto name = map["Name"].toString();
QJsonValue intervalVal = obj["backupInterval"];
if (intervalVal.isString()) {
interval = intervalVal.toString().toInt();
} else {
interval = intervalVal.toInt();
}
QJsonValue countVal = obj["maxBackupVersions"];
if (countVal.isString()) {
count = countVal.toString().toInt();
} else {
count = countVal.toInt();
}
auto name = obj["Name"].toString();
auto format = name.replace(" ", "_").toLower(); auto format = name.replace(" ", "_").toLower();
qCDebug(domain_server) << " Name:" << name; qCDebug(domain_server) << " Name:" << name;
@ -113,9 +95,6 @@ void DomainContentBackupManager::parseSettings(const QJsonObject& settings) {
_backupRules.push_back(newRule); _backupRules.push_back(newRule);
} }
} else {
qCDebug(domain_server) << "BACKUP RULES: NONE";
}
} }
void DomainContentBackupManager::refreshBackupRules() { void DomainContentBackupManager::refreshBackupRules() {

View file

@ -50,7 +50,7 @@ public:
static const int DEFAULT_PERSIST_INTERVAL; static const int DEFAULT_PERSIST_INTERVAL;
DomainContentBackupManager(const QString& rootBackupDirectory, DomainContentBackupManager(const QString& rootBackupDirectory,
const QJsonObject& settings, const QVariantList& settings,
int persistInterval = DEFAULT_PERSIST_INTERVAL, int persistInterval = DEFAULT_PERSIST_INTERVAL,
bool debugTimestampNow = false); bool debugTimestampNow = false);
@ -82,7 +82,7 @@ protected:
void refreshBackupRules(); void refreshBackupRules();
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);
void parseSettings(const QJsonObject& settings); void parseBackupRules(const QVariantList& backupRules);
std::pair<bool, QString> createBackup(const QString& prefix, const QString& name); std::pair<bool, QString> createBackup(const QString& prefix, const QString& name);

View file

@ -297,14 +297,11 @@ DomainServer::DomainServer(int argc, char* argv[]) :
} }
maybeHandleReplacementEntityFile(); maybeHandleReplacementEntityFile();
auto contentArchivesGroup = _settingsManager.valueOrDefaultValueForKeyPath(AUTOMATIC_CONTENT_ARCHIVES_GROUP);
auto archivesIntervalObject = QJsonObject();
if (contentArchivesGroup.canConvert<QVariantMap>()) { static const QString BACKUP_RULES_KEYPATH = AUTOMATIC_CONTENT_ARCHIVES_GROUP + ".backup_rules";
archivesIntervalObject = QJsonObject::fromVariantMap(contentArchivesGroup.toMap()); auto backupRulesVariant = _settingsManager.valueOrDefaultValueForKeyPath(BACKUP_RULES_KEYPATH);
}
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), archivesIntervalObject)); _contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), backupRulesVariant.toList()));
connect(_contentManager.get(), &DomainContentBackupManager::started, _contentManager.get(), [this](){ connect(_contentManager.get(), &DomainContentBackupManager::started, _contentManager.get(), [this](){
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath()))); _contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));