private void DoTransmission(Database db, EmailNotifications emailSettings) { sendAttempts++; new Log("FTP transmission for \"" + db.GetAlias() + "\" started."); try { using (Session session = new Session()) { session.Open(sessionOptions); TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; TransferOperationResult transferResult; transferResult = session.PutFiles(db.GetFile(), "DB_" + db.GetAlias() + "_bu" + DateTime.Now.ToString("yyyyMMddHHmm") + ".sql", false, transferOptions); transferResult.Check(); new Log("FTP transmission for \"" + db.GetAlias() + "\" completed successfully."); session.Close(); emailSettings.NotifyCheck(db.GetAlias(), EmailNotifications.FTP_OPERATION_OK); } } catch (Exception ex) { if (sendAttempts < 6) { DoTransmission(db, emailSettings); } else { new Log("ERROR: FTP transmission for \"" + db.GetAlias() + "\" failed."); emailSettings.NotifyCheck(db.GetAlias(), EmailNotifications.FTP_OPERATION_FAIL); } } }
private void DoBackup(object sender, DoWorkEventArgs e) { attempts++; new Log("Back-up operation for \"" + alias + "\" started."); RaiseDoingBackup(); using (connection) { using (MySqlCommand cmd = new MySqlCommand()) { using (MySqlBackup mb = new MySqlBackup(cmd)) { try { cmd.Connection = connection; connection.Open(); mb.ExportToFile(file); connection.Close(); new Log("Back-up operation for \"" + alias + "\" completed successfully."); emailSettings.NotifyCheck(alias, EmailNotifications.BACKUP_OPERATION_OK); cryptographySettings.SetFile(file); cryptographySettings.SetMode(Cryptography.ENCRYPT); cryptographySettings.DoCryptography(); DeleteOldFiles(); ftpSettings.Transmission(this, emailSettings); DeleteAfterBackup(); ftpSettings.DeleteOld(this); } catch (Exception ex) { if (attempts < 6) { DoBackup(sender, e); } else { new Log("ERROR: Back-up operation for \"" + alias + "\" failed."); emailSettings.NotifyCheck(alias, EmailNotifications.BACKUP_OPERATION_FAIL); } } } } } RaiseFinished(); }
private void DoTransmission(Database db,EmailNotifications emailSettings) { sendAttempts++; new Log("FTP transmission for \"" + db.GetAlias() + "\" started."); try { using (Session session = new Session()) { session.Open(sessionOptions); TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; TransferOperationResult transferResult; transferResult = session.PutFiles(db.GetFile(), "DB_" + db.GetAlias() + "_bu" + DateTime.Now.ToString("yyyyMMddHHmm") + ".sql", false, transferOptions); transferResult.Check(); new Log("FTP transmission for \"" + db.GetAlias() + "\" completed successfully."); session.Close(); emailSettings.NotifyCheck(db.GetAlias(),EmailNotifications.FTP_OPERATION_OK); } } catch (Exception ex) { if (sendAttempts < 6) DoTransmission(db,emailSettings); else { new Log("ERROR: FTP transmission for \"" + db.GetAlias() + "\" failed."); emailSettings.NotifyCheck(db.GetAlias(), EmailNotifications.FTP_OPERATION_FAIL); } } }