public void ModifyDeleteBackupsOlderThanDaysTest() { ConfigurationXmlHandler.SetDeleteBackupsOlderThanDays(14); XmlDocument document = new XmlDocument(); document.Load(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MySQLBackup\Configuration\Configuration.xml"); XmlNode deleteBackupsOlderThanNode = document.SelectSingleNode("Configuration/DeleteBackupsOlderThan"); Assert.AreEqual("14", deleteBackupsOlderThanNode.InnerText); ConfigurationXmlHandler.SetDeleteBackupsOlderThanDays(7); }
/// <summary> /// Handles the Click event of the SelectBackupDumpFileButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void SelectBackupDumpFileButton_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.InitialDirectory = ConfigurationXmlHandler.GetBackupLocation(); dlg.DefaultExt = ".dump"; dlg.Filter = "Backup Dump Files (*.dump)|*.dump|SQL Dump Files (*.sql)|*.sql"; Boolean?hasSelected = dlg.ShowDialog(); if (hasSelected == true) { TextRestoreFile.Text = dlg.FileName; } }
public void ModifyBackupLocationTest() { ConfigurationXmlHandler.SetBackupLocation(@"C:\MyTestBackupLocation"); XmlDocument document = new XmlDocument(); document.Load(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MySQLBackup\Configuration\Configuration.xml"); XmlNode backupLocationNode = document.SelectSingleNode("Configuration/BackupLocation"); Assert.AreEqual(@"C:\MyTestBackupLocation\", backupLocationNode.InnerText); //Delete the test directory Directory.Delete(@"C:\MyTestBackupLocation\"); ConfigurationXmlHandler.SetBackupLocation(@"C:\ProgramData\MySQLBackup\Backup\"); }
/// <summary> /// Creates the backup location. /// </summary> /// <param name="hostName">Name of the host.</param> /// <param name="databaseName">Name of the database.</param> /// <param name="backupLocation">The backup location.</param> /// <returns></returns> private bool CreateBackupLocation(string hostName, string databaseName, out string backupLocation) { bool error = false; backupLocation = ConfigurationXmlHandler.GetBackupLocation() + hostName + @"\" + databaseName + @"\"; if (!Directory.Exists(backupLocation)) { try { Directory.CreateDirectory(Path.GetDirectoryName(backupLocation)); } catch (Exception ex) { error = true; new LogHandler().LogMessage(LogHandler.MessageType.ERROR, "Cannot create directory " + backupLocation + Environment.NewLine + ex.ToString()); } } return(!error); }
/// <summary> /// Deletes the old backup files. /// </summary> private void DeleteOldBackupFiles() { logHandler = new LogHandler(); int days = ConfigurationXmlHandler.GetDeleteBackupsOlderThanDays(); string backupLocation = ConfigurationXmlHandler.GetBackupLocation(); if (days > 0) { try { ProcessDeleteFiles(backupLocation, days + 1); //Add 1 to number of days, since it has to delete files older than the specified number of days logHandler.LogMessage(LogHandler.MessageType.INFO, string.Format("Cleaned up backup files older than {0} days", days)); } catch (Exception ex) { logHandler.LogMessage(LogHandler.MessageType.ERROR, string.Format("Error while cleaning up files older than {0} days: {1}", days, ex.ToString())); } } }
/** * Synchronise with the values from the Configuration file. */ private void SyncFromConfiguration() { this.backupLocation = ConfigurationXmlHandler.GetBackupLocation(); this.deleteBackupAfterDays = ConfigurationXmlHandler.GetDeleteBackupsOlderThanDays(); }
public void RetrieveDeleteBackupOlderThanDaysTest() { int days = ConfigurationXmlHandler.GetDeleteBackupsOlderThanDays(); Assert.AreEqual(7, days); }
public void RetrieveBackupLocationTest() { string backupLocation = ConfigurationXmlHandler.GetBackupLocation(); Assert.AreEqual(@"C:\ProgramData\MySQLBackup\Backup\", backupLocation); }