@@ -1118,108 +1118,111 @@ void MainWorker::HandleAutomaticBackups()
1118
1118
int nValue=0 ;
1119
1119
if (!m_sql.GetPreferencesVar (" UseAutoBackup" ,nValue))
1120
1120
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;
1126
1129
1127
1130
#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\\ " ;
1131
1134
#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/" ;
1135
1138
#endif
1136
1139
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 ();
1140
1143
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 );
1145
1148
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 ;
1152
1155
1153
- int lastHourBackup = -1 ;
1154
- int lastDayBackup = -1 ;
1155
- int lastMonthBackup = -1 ;
1156
+ int lastHourBackup = -1 ;
1157
+ int lastDayBackup = -1 ;
1158
+ int lastMonthBackup = -1 ;
1156
1159
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);
1160
1163
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)) {
1164
1167
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" ;
1169
1172
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);
1178
1176
}
1179
1177
else {
1180
- _log.Log (LOG_ERROR," Error accessing automatic backup directories " );
1178
+ _log.Log (LOG_ERROR," Error writing automatic hourly backup file " );
1181
1179
}
1180
+ closedir (lDir);
1181
+ }
1182
+ else {
1183
+ _log.Log (LOG_ERROR," Error accessing automatic backup directories" );
1182
1184
}
1183
- if ((lastDayBackup == -1 )||(lastDayBackup !=day)) {
1185
+ }
1186
+ if ((lastDayBackup == -1 )||(lastDayBackup !=day)) {
1184
1187
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" ;
1189
1192
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);
1198
1196
}
1199
1197
else {
1200
- _log.Log (LOG_ERROR," Error accessing automatic backup directories " );
1198
+ _log.Log (LOG_ERROR," Error writing automatic daily backup file " );
1201
1199
}
1200
+ closedir (lDir);
1202
1201
}
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" ;
1208
1211
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);
1217
1215
}
1218
1216
else {
1219
- _log.Log (LOG_ERROR," Error accessing automatic backup directories " );
1217
+ _log.Log (LOG_ERROR," Error writing automatic monthly backup file " );
1220
1218
}
1219
+ closedir (lDir);
1220
+ }
1221
+ else {
1222
+ _log.Log (LOG_ERROR," Error accessing automatic backup directories" );
1221
1223
}
1222
1224
}
1225
+ _log.Log (LOG_STATUS, " Ending automatic database backup procedure..." );
1223
1226
}
1224
1227
1225
1228
void MainWorker::ParseRFXLogFile ()
0 commit comments