/// <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;
            }
        }
        /// <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);
        }
Exemplo n.º 3
0
        /// <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();
 }
Exemplo n.º 5
0
        public void RetrieveBackupLocationTest()
        {
            string backupLocation = ConfigurationXmlHandler.GetBackupLocation();

            Assert.AreEqual(@"C:\ProgramData\MySQLBackup\Backup\", backupLocation);
        }