mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
added support for rolling version numbers in backups
This commit is contained in:
parent
b511f868d5
commit
f44513ebe7
5 changed files with 74 additions and 11 deletions
|
@ -1047,6 +1047,10 @@ void OctreeServer::readConfiguration() {
|
||||||
_backupInterval = OctreePersistThread::DEFAULT_BACKUP_INTERVAL;
|
_backupInterval = OctreePersistThread::DEFAULT_BACKUP_INTERVAL;
|
||||||
readOptionInt(QString("backupInterval"), settingsSectionObject, _backupInterval);
|
readOptionInt(QString("backupInterval"), settingsSectionObject, _backupInterval);
|
||||||
qDebug() << "backupInterval=" << _backupInterval;
|
qDebug() << "backupInterval=" << _backupInterval;
|
||||||
|
|
||||||
|
_maxBackupVersions = OctreePersistThread::DEFAULT_MAX_BACKUP_VERSIONS;
|
||||||
|
readOptionInt(QString("maxBackupVersions"), settingsSectionObject, _maxBackupVersions);
|
||||||
|
qDebug() << "maxBackupVersions=" << _maxBackupVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1133,7 +1137,7 @@ void OctreeServer::run() {
|
||||||
|
|
||||||
// now set up PersistThread
|
// now set up PersistThread
|
||||||
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
||||||
_wantBackup, _backupInterval, _backupExtensionFormat);
|
_wantBackup, _backupInterval, _backupExtensionFormat, _maxBackupVersions);
|
||||||
if (_persistThread) {
|
if (_persistThread) {
|
||||||
_persistThread->initialize(true);
|
_persistThread->initialize(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,7 @@ protected:
|
||||||
bool _wantBackup;
|
bool _wantBackup;
|
||||||
QString _backupExtensionFormat;
|
QString _backupExtensionFormat;
|
||||||
int _backupInterval;
|
int _backupInterval;
|
||||||
|
int _maxBackupVersions;
|
||||||
|
|
||||||
static OctreeServer* _instance;
|
static OctreeServer* _instance;
|
||||||
|
|
||||||
|
|
|
@ -302,9 +302,9 @@
|
||||||
{
|
{
|
||||||
"name": "backupExtensionFormat",
|
"name": "backupExtensionFormat",
|
||||||
"label": "Backup File Extension Format:",
|
"label": "Backup File Extension Format:",
|
||||||
"help": "Format used to create the extension for the backup of your persisted entities.",
|
"help": "Format used to create the extension for the backup of your persisted entities. Use a format with %N to get rolling. Or use date formatting like %Y-%m-%d.%H:%M:%S.%z",
|
||||||
"placeholder": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
"placeholder": ".backup.%N",
|
||||||
"default": ".backup.%Y-%m-%d.%H:%M:%S.%z",
|
"default": ".backup.%N",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -315,6 +315,14 @@
|
||||||
"default": "1800000",
|
"default": "1800000",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "maxBackupVersions",
|
||||||
|
"label": "Max Rolled Backup Versions",
|
||||||
|
"help": "If your backup extension format uses 'rolling', how many versions do you want us to keep?",
|
||||||
|
"placeholder": "5",
|
||||||
|
"default": "5",
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "NoBackup",
|
"name": "NoBackup",
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
|
|
|
@ -12,21 +12,26 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
#include <SharedUtil.h>
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
#include "OctreePersistThread.h"
|
#include "OctreePersistThread.h"
|
||||||
|
|
||||||
const int OctreePersistThread::DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
|
const int OctreePersistThread::DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
|
||||||
const int OctreePersistThread::DEFAULT_BACKUP_INTERVAL = 1000 * 60 * 30; // every 30 minutes
|
const int OctreePersistThread::DEFAULT_BACKUP_INTERVAL = 1000 * 60 * 1; // 30; // every 30 minutes
|
||||||
const QString OctreePersistThread::DEFAULT_BACKUP_EXTENSION_FORMAT(".backup.%Y-%m-%d.%H:%M:%S.%z");
|
const QString OctreePersistThread::DEFAULT_BACKUP_EXTENSION_FORMAT(".backup.%N");
|
||||||
|
const int OctreePersistThread::DEFAULT_MAX_BACKUP_VERSIONS = 5;
|
||||||
|
|
||||||
|
|
||||||
OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, int persistInterval,
|
OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, int persistInterval,
|
||||||
bool wantBackup, int backupInterval, const QString& backupExtensionFormat) :
|
bool wantBackup, int backupInterval, const QString& backupExtensionFormat,
|
||||||
|
int maxBackupVersions) :
|
||||||
_tree(tree),
|
_tree(tree),
|
||||||
_filename(filename),
|
_filename(filename),
|
||||||
_backupExtensionFormat(backupExtensionFormat),
|
_backupExtensionFormat(backupExtensionFormat),
|
||||||
|
_maxBackupVersions(maxBackupVersions),
|
||||||
_persistInterval(persistInterval),
|
_persistInterval(persistInterval),
|
||||||
_backupInterval(backupInterval),
|
_backupInterval(backupInterval),
|
||||||
_initialLoadComplete(false),
|
_initialLoadComplete(false),
|
||||||
|
@ -131,6 +136,37 @@ void OctreePersistThread::persist() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OctreePersistThread::rollOldBackupVersions() {
|
||||||
|
if (!_backupExtensionFormat.contains("%N")) {
|
||||||
|
return; // this backup extension format doesn't support rolling
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Rolling old backup versions...";
|
||||||
|
for(int n = _maxBackupVersions - 1; n > 0; n--) {
|
||||||
|
QString backupExtensionN = _backupExtensionFormat;
|
||||||
|
QString backupExtensionNplusOne = _backupExtensionFormat;
|
||||||
|
backupExtensionN.replace(QString("%N"), QString::number(n));
|
||||||
|
backupExtensionNplusOne.replace(QString("%N"), QString::number(n+1));
|
||||||
|
|
||||||
|
QString backupFilenameN = _filename + backupExtensionN;
|
||||||
|
QString backupFilenameNplusOne = _filename + backupExtensionNplusOne;
|
||||||
|
|
||||||
|
QFile backupFileN(backupFilenameN);
|
||||||
|
|
||||||
|
if (backupFileN.exists()) {
|
||||||
|
qDebug() << "rolling backup file " << backupFilenameN << "to" << backupFilenameNplusOne << "...";
|
||||||
|
int result = rename(qPrintable(backupFilenameN), qPrintable(backupFilenameNplusOne));
|
||||||
|
if (result == 0) {
|
||||||
|
qDebug() << "DONE rolling backup file " << backupFilenameN << "to" << backupFilenameNplusOne << "...";
|
||||||
|
} else {
|
||||||
|
qDebug() << "ERROR in rolling backup file " << backupFilenameN << "to" << backupFilenameNplusOne << "...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << "Done rolling old backup versions...";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void OctreePersistThread::backup() {
|
void OctreePersistThread::backup() {
|
||||||
if (_wantBackup) {
|
if (_wantBackup) {
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
|
@ -141,10 +177,20 @@ void OctreePersistThread::backup() {
|
||||||
if (sinceLastBackup > intervalToBackup) {
|
if (sinceLastBackup > intervalToBackup) {
|
||||||
struct tm* localTime = localtime(&_lastPersistTime);
|
struct tm* localTime = localtime(&_lastPersistTime);
|
||||||
|
|
||||||
|
QString backupFileName;
|
||||||
|
|
||||||
|
// check to see if they asked for version rolling format
|
||||||
|
if (_backupExtensionFormat.contains("%N")) {
|
||||||
|
rollOldBackupVersions(); // rename all the old backup files accordingly
|
||||||
|
QString backupExtension = _backupExtensionFormat;
|
||||||
|
backupExtension.replace(QString("%N"), QString("1"));
|
||||||
|
backupFileName = _filename + backupExtension;
|
||||||
|
} else {
|
||||||
char backupExtension[256];
|
char backupExtension[256];
|
||||||
strftime(backupExtension, sizeof(backupExtension), qPrintable(_backupExtensionFormat), localTime);
|
strftime(backupExtension, sizeof(backupExtension), qPrintable(_backupExtensionFormat), localTime);
|
||||||
|
backupFileName = _filename + backupExtension;
|
||||||
|
}
|
||||||
|
|
||||||
QString backupFileName = _filename + backupExtension;
|
|
||||||
|
|
||||||
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
|
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
|
||||||
int result = rename(qPrintable(_filename), qPrintable(backupFileName));
|
int result = rename(qPrintable(_filename), qPrintable(backupFileName));
|
||||||
|
|
|
@ -25,10 +25,12 @@ public:
|
||||||
static const int DEFAULT_PERSIST_INTERVAL;
|
static const int DEFAULT_PERSIST_INTERVAL;
|
||||||
static const int DEFAULT_BACKUP_INTERVAL;
|
static const int DEFAULT_BACKUP_INTERVAL;
|
||||||
static const QString DEFAULT_BACKUP_EXTENSION_FORMAT;
|
static const QString DEFAULT_BACKUP_EXTENSION_FORMAT;
|
||||||
|
static const int DEFAULT_MAX_BACKUP_VERSIONS;
|
||||||
|
|
||||||
OctreePersistThread(Octree* tree, const QString& filename, int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
OctreePersistThread(Octree* tree, const QString& filename, int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||||
bool wantBackup = false, int backupInterval = DEFAULT_BACKUP_INTERVAL,
|
bool wantBackup = false, int backupInterval = DEFAULT_BACKUP_INTERVAL,
|
||||||
const QString& backupExtensionFormat = DEFAULT_BACKUP_EXTENSION_FORMAT);
|
const QString& backupExtensionFormat = DEFAULT_BACKUP_EXTENSION_FORMAT,
|
||||||
|
int maxBackupVersions = DEFAULT_MAX_BACKUP_VERSIONS);
|
||||||
|
|
||||||
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
||||||
quint64 getLoadElapsedTime() const { return _loadTimeUSecs; }
|
quint64 getLoadElapsedTime() const { return _loadTimeUSecs; }
|
||||||
|
@ -44,10 +46,12 @@ protected:
|
||||||
|
|
||||||
void persist();
|
void persist();
|
||||||
void backup();
|
void backup();
|
||||||
|
void rollOldBackupVersions();
|
||||||
private:
|
private:
|
||||||
Octree* _tree;
|
Octree* _tree;
|
||||||
QString _filename;
|
QString _filename;
|
||||||
QString _backupExtensionFormat;
|
QString _backupExtensionFormat;
|
||||||
|
int _maxBackupVersions;
|
||||||
int _persistInterval;
|
int _persistInterval;
|
||||||
int _backupInterval;
|
int _backupInterval;
|
||||||
bool _initialLoadComplete;
|
bool _initialLoadComplete;
|
||||||
|
|
Loading…
Reference in a new issue