private void SalvarConfiguracaoBackup_Click(object sender, EventArgs e) { Backup backup = Firebird.RetornaBackup(); if (backup == null && chkAtivarBackup.Checked) { backup = new Backup(); //backup.Ativo = 1; backup.Periodo = cmbPeriodo.SelectedIndex; backup.CaminhoBackup = CaminhoBackup.Text; bool retorno = Firebird.SaveBackup(backup); if (retorno) { MessageBox.Show("Backup Salvo com Sucesso.", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show("Erro ao tentar salvar o backup. Verifique o log de erro para obter mais informações.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (chkAtivarBackup.Checked) { //backup.Ativo = 1; backup.Periodo = cmbPeriodo.SelectedIndex; backup.CaminhoBackup = CaminhoBackup.Text; string data = DateTime.Now.ToString(); backup.DataUltimoBackup = data.Substring(0, 10); bool retorno = Firebird.AlterarDataUltimoBackup(backup.DataUltimoBackup); if (retorno) { MessageBox.Show("Alterado as configurações do Backup", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.None); } else { MessageBox.Show("Erro ao tentar alterar o backup!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (backup != null && chkAtivarBackup.Checked == false) { if (MessageBox.Show("Você desativou o backup automático.Deseja confirmar?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Firebird.DeletaBackup(); } } }
private void CheckBackUp() { try { Backup backup = Firebird.RetornaBackup(); if (backup != null) { if (Directory.Exists(backup.CaminhoBackup)) { switch (backup.Periodo) { case 0: if (backup.DataUltimoBackup == "") { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } else { DateTime data = Convert.ToDateTime(backup.DataUltimoBackup); data = data.AddDays(+1); if (DateTime.Today == data || DateTime.Today > data) { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } } break; case 1: if (backup.DataUltimoBackup == "") { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } else { DateTime data = Convert.ToDateTime(backup.DataUltimoBackup); data = data.AddDays(+7); if (DateTime.Today == data || DateTime.Today > data) { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } } break; case 2: if (backup.DataUltimoBackup == "") { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } else { DateTime data = Convert.ToDateTime(backup.DataUltimoBackup); data = data.AddDays(+30); if (DateTime.Today == data || DateTime.Today > data) { FbBackup backupSvc = new FbBackup(); string NomeArquivo = backup.CaminhoBackup + "/BackUp DL 2020 - Dia " + DateTime.Today.Day.ToString("0,0") + "_" + DateTime.Today.Month.ToString("0,0") + ".dl"; if (File.Exists(NomeArquivo)) { File.Delete(NomeArquivo); } backupSvc.ConnectionString = Firebird.Conn; backupSvc.Verbose = true; backupSvc.BackupFiles.Add(new FbBackupFile(NomeArquivo, -1)); backupSvc.Execute(); string date = DateTime.Today.ToString(); backup.DataUltimoBackup = date; Firebird.AlterarDataUltimoBackup(date); Firebird.SaveBackup(backup); } } break; } } else { DialogResult result = MessageBox.Show( "O caminho para o backup automático não está disponivel, deseja continuar?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { Process.GetCurrentProcess().Kill(); } else { } } } } catch { } }