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,59 +62,38 @@ 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"; qCDebug(domain_server) << "BACKUP RULES:";
if (settings[BACKUP_RULES_KEY].isArray()) {
const QJsonArray& backupRules = settings[BACKUP_RULES_KEY].toArray();
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();
auto format = name.replace(" ", "_").toLower();
QJsonValue intervalVal = obj["backupInterval"]; qCDebug(domain_server) << " Name:" << name;
if (intervalVal.isString()) { qCDebug(domain_server) << " format:" << format;
interval = intervalVal.toString().toInt(); qCDebug(domain_server) << " interval:" << interval;
} else { qCDebug(domain_server) << " count:" << count;
interval = intervalVal.toInt();
}
QJsonValue countVal = obj["maxBackupVersions"]; BackupRule newRule = { name, interval, format, count, 0 };
if (countVal.isString()) {
count = countVal.toString().toInt();
} else {
count = countVal.toInt();
}
auto name = obj["Name"].toString(); newRule.lastBackupSeconds = getMostRecentBackupTimeInSecs(format);
auto format = name.replace(" ", "_").toLower();
qCDebug(domain_server) << " Name:" << name; if (newRule.lastBackupSeconds > 0) {
qCDebug(domain_server) << " format:" << format; auto now = QDateTime::currentSecsSinceEpoch();
qCDebug(domain_server) << " interval:" << interval; auto sinceLastBackup = now - newRule.lastBackupSeconds;
qCDebug(domain_server) << " count:" << count; qCDebug(domain_server).noquote() << " lastBackup:" << formatSecTime(sinceLastBackup) << "ago";
} else {
BackupRule newRule = { name, interval, format, count, 0 }; qCDebug(domain_server) << " lastBackup: NEVER";
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);
} }
} else {
qCDebug(domain_server) << "BACKUP RULES: NONE"; _backupRules.push_back(newRule);
} }
} }

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

@ -296,15 +296,12 @@ DomainServer::DomainServer(int argc, char* argv[]) :
qCDebug(domain_server) << "Created entities data directory"; qCDebug(domain_server) << "Created entities data directory";
} }
maybeHandleReplacementEntityFile(); 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](){ connect(_contentManager.get(), &DomainContentBackupManager::started, _contentManager.get(), [this](){
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath()))); _contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));