Skip to content

Commit 97c5a82

Browse files
committed
Added log messages to the automatic database backup routines (this routine should be double checked for workings)
1 parent 427b757 commit 97c5a82

File tree

1 file changed

+77
-74
lines changed

1 file changed

+77
-74
lines changed

main/mainworker.cpp

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,108 +1118,111 @@ void MainWorker::HandleAutomaticBackups()
11181118
int nValue=0;
11191119
if (!m_sql.GetPreferencesVar("UseAutoBackup",nValue))
11201120
return;
1121-
if (nValue==1)
1122-
{
1123-
std::stringstream backup_DirH;
1124-
std::stringstream backup_DirD;
1125-
std::stringstream backup_DirM;
1121+
if (nValue != 1)
1122+
return;
1123+
1124+
_log.Log(LOG_STATUS, "Starting automatic database backup procedure...");
1125+
1126+
std::stringstream backup_DirH;
1127+
std::stringstream backup_DirD;
1128+
std::stringstream backup_DirM;
11261129

11271130
#ifdef WIN32
1128-
backup_DirH << szUserDataFolder << "backups\\hourly\\";
1129-
backup_DirD << szUserDataFolder << "backups\\daily\\";
1130-
backup_DirM << szUserDataFolder << "backups\\monthly\\";
1131+
backup_DirH << szUserDataFolder << "backups\\hourly\\";
1132+
backup_DirD << szUserDataFolder << "backups\\daily\\";
1133+
backup_DirM << szUserDataFolder << "backups\\monthly\\";
11311134
#else
1132-
backup_DirH << szUserDataFolder << "backups/hourly/";
1133-
backup_DirD << szUserDataFolder << "backups/daily/";
1134-
backup_DirM << szUserDataFolder << "backups/monthly/";
1135+
backup_DirH << szUserDataFolder << "backups/hourly/";
1136+
backup_DirD << szUserDataFolder << "backups/daily/";
1137+
backup_DirM << szUserDataFolder << "backups/monthly/";
11351138
#endif
11361139

1137-
std::string sbackup_DirH = backup_DirH.str();
1138-
std::string sbackup_DirD = backup_DirD.str();
1139-
std::string sbackup_DirM = backup_DirM.str();
1140+
std::string sbackup_DirH = backup_DirH.str();
1141+
std::string sbackup_DirD = backup_DirD.str();
1142+
std::string sbackup_DirM = backup_DirM.str();
11401143

1141-
//create folders if they not exists
1142-
mkdir_deep(sbackup_DirH.c_str(), 0755);
1143-
mkdir_deep(sbackup_DirD.c_str(), 0755);
1144-
mkdir_deep(sbackup_DirM.c_str(), 0755);
1144+
//create folders if they not exists
1145+
mkdir_deep(sbackup_DirH.c_str(), 0755);
1146+
mkdir_deep(sbackup_DirD.c_str(), 0755);
1147+
mkdir_deep(sbackup_DirM.c_str(), 0755);
11451148

1146-
time_t now = mytime(NULL);
1147-
struct tm tm1;
1148-
localtime_r(&now,&tm1);
1149-
int hour = tm1.tm_hour;
1150-
int day = tm1.tm_mday;
1151-
int month = tm1.tm_mon;
1149+
time_t now = mytime(NULL);
1150+
struct tm tm1;
1151+
localtime_r(&now,&tm1);
1152+
int hour = tm1.tm_hour;
1153+
int day = tm1.tm_mday;
1154+
int month = tm1.tm_mon;
11521155

1153-
int lastHourBackup = -1;
1154-
int lastDayBackup = -1;
1155-
int lastMonthBackup = -1;
1156+
int lastHourBackup = -1;
1157+
int lastDayBackup = -1;
1158+
int lastMonthBackup = -1;
11561159

1157-
m_sql.GetLastBackupNo("Hour", lastHourBackup);
1158-
m_sql.GetLastBackupNo("Day", lastDayBackup);
1159-
m_sql.GetLastBackupNo("Month", lastMonthBackup);
1160+
m_sql.GetLastBackupNo("Hour", lastHourBackup);
1161+
m_sql.GetLastBackupNo("Day", lastDayBackup);
1162+
m_sql.GetLastBackupNo("Month", lastMonthBackup);
11601163

1161-
DIR *lDir;
1162-
//struct dirent *ent;
1163-
if ((lastHourBackup == -1)||(lastHourBackup !=hour)) {
1164+
DIR *lDir;
1165+
//struct dirent *ent;
1166+
if ((lastHourBackup == -1)||(lastHourBackup !=hour)) {
11641167

1165-
if ((lDir = opendir(sbackup_DirH.c_str())) != NULL)
1166-
{
1167-
std::stringstream sTmp;
1168-
sTmp << "backup-hour-" << hour << ".db";
1168+
if ((lDir = opendir(sbackup_DirH.c_str())) != NULL)
1169+
{
1170+
std::stringstream sTmp;
1171+
sTmp << "backup-hour-" << hour << ".db";
11691172

1170-
std::string OutputFileName=sbackup_DirH + sTmp.str();
1171-
if (m_sql.BackupDatabase(OutputFileName)) {
1172-
m_sql.SetLastBackupNo("Hour", hour);
1173-
}
1174-
else {
1175-
_log.Log(LOG_ERROR,"Error writing automatic hourly backup file");
1176-
}
1177-
closedir(lDir);
1173+
std::string OutputFileName=sbackup_DirH + sTmp.str();
1174+
if (m_sql.BackupDatabase(OutputFileName)) {
1175+
m_sql.SetLastBackupNo("Hour", hour);
11781176
}
11791177
else {
1180-
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
1178+
_log.Log(LOG_ERROR,"Error writing automatic hourly backup file");
11811179
}
1180+
closedir(lDir);
1181+
}
1182+
else {
1183+
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
11821184
}
1183-
if ((lastDayBackup == -1)||(lastDayBackup !=day)) {
1185+
}
1186+
if ((lastDayBackup == -1)||(lastDayBackup !=day)) {
11841187

1185-
if ((lDir = opendir(sbackup_DirD.c_str())) != NULL)
1186-
{
1187-
std::stringstream sTmp;
1188-
sTmp << "backup-day-" << day << ".db";
1188+
if ((lDir = opendir(sbackup_DirD.c_str())) != NULL)
1189+
{
1190+
std::stringstream sTmp;
1191+
sTmp << "backup-day-" << day << ".db";
11891192

1190-
std::string OutputFileName=sbackup_DirD + sTmp.str();
1191-
if (m_sql.BackupDatabase(OutputFileName)) {
1192-
m_sql.SetLastBackupNo("Day", day);
1193-
}
1194-
else {
1195-
_log.Log(LOG_ERROR,"Error writing automatic daily backup file");
1196-
}
1197-
closedir(lDir);
1193+
std::string OutputFileName=sbackup_DirD + sTmp.str();
1194+
if (m_sql.BackupDatabase(OutputFileName)) {
1195+
m_sql.SetLastBackupNo("Day", day);
11981196
}
11991197
else {
1200-
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
1198+
_log.Log(LOG_ERROR,"Error writing automatic daily backup file");
12011199
}
1200+
closedir(lDir);
12021201
}
1203-
if ((lastMonthBackup == -1)||(lastMonthBackup !=month)) {
1204-
if ((lDir = opendir(sbackup_DirM.c_str())) != NULL)
1205-
{
1206-
std::stringstream sTmp;
1207-
sTmp << "backup-month-" << month+1 << ".db";
1202+
else {
1203+
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
1204+
}
1205+
}
1206+
if ((lastMonthBackup == -1)||(lastMonthBackup !=month)) {
1207+
if ((lDir = opendir(sbackup_DirM.c_str())) != NULL)
1208+
{
1209+
std::stringstream sTmp;
1210+
sTmp << "backup-month-" << month+1 << ".db";
12081211

1209-
std::string OutputFileName=sbackup_DirM + sTmp.str();
1210-
if (m_sql.BackupDatabase(OutputFileName)) {
1211-
m_sql.SetLastBackupNo("Month", month);
1212-
}
1213-
else {
1214-
_log.Log(LOG_ERROR,"Error writing automatic monthly backup file");
1215-
}
1216-
closedir(lDir);
1212+
std::string OutputFileName=sbackup_DirM + sTmp.str();
1213+
if (m_sql.BackupDatabase(OutputFileName)) {
1214+
m_sql.SetLastBackupNo("Month", month);
12171215
}
12181216
else {
1219-
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
1217+
_log.Log(LOG_ERROR,"Error writing automatic monthly backup file");
12201218
}
1219+
closedir(lDir);
1220+
}
1221+
else {
1222+
_log.Log(LOG_ERROR,"Error accessing automatic backup directories");
12211223
}
12221224
}
1225+
_log.Log(LOG_STATUS, "Ending automatic database backup procedure...");
12231226
}
12241227

12251228
void MainWorker::ParseRFXLogFile()

0 commit comments

Comments
 (0)