Ejemplo n.º 1
0
        /// <summary>
        /// Prepares and executes robocopy backup command.
        /// </summary>
        /// <param name="task"><see cref="Task"/> to run.</param>
        public static void RunBackup(Task task)
        {
            string timestamp  = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
            string logFile    = GetLogName(task.Guid, timestamp);
            string destDir    = Path.Combine(task.Destination, timestamp);
            string latestLink = Path.Combine(task.Destination, "latest");

            try {
                if (task.Method == Method.Differential && task.Retention > 1)
                {
                    try {
                        CopyDirectoryStructure(latestLink, destDir);
                        CopyHardlinkStructure(latestLink, destDir);
                    } catch { /* Ignore if the latestLink doesn't exist or points to invalid directory */ }
                }
                string uncPath = Unc.IsUncPath(task.Source) ? task.Source : Unc.IsUncPath(task.Destination) ? task.Destination : null;
                using (Unc unc = new Unc(uncPath)) {
                    unc.Connect(Credential.Decrypt(task.Guid, task.Credential));
                    RunRobocopy(task, logFile, destDir);
                }
                if (task.Retention > 1)
                {
                    CreateLatestSymlink(destDir, latestLink);
                    DeleteOldDirs(task.Destination, task.Retention);
                }
            } catch (Exception e) {
                using (StreamWriter streamWriter = new StreamWriter(logFile, true)) {
                    streamWriter.Write(e.Message);
                    streamWriter.Write(e.StackTrace);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// <see cref="sourceButton.Click"/> event handler. Displays source folder selection dialog.
 /// </summary>
 private void SourceButton_Click(object sender, EventArgs e)
 {
     if (sourceFolderBrowserDialog.ShowDialog() == DialogResult.OK)
     {
         sourceTextBox.Text = sourceFolderBrowserDialog.SelectedPath = Unc.TranslatePath(sourceFolderBrowserDialog.SelectedPath);
         PopulateSourceTreeView();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Enables or disables network credentials controls based on the source and destination directory UNC conformance.
        /// </summary>
        private void CheckUncPath()
        {
            bool unc = Unc.IsUncPath(sourceTextBox.Text) || Unc.IsUncPath(destinationTextBox.Text);

            usernameTextBox.Enabled = unc;
            passwordTextBox.Enabled = unc;
            if (!unc)
            {
                usernameTextBox.Text = string.Empty;
                passwordTextBox.Text = string.Empty;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// <see cref="destinationButton.Click"/> event handler. Displays destination folder selection dialog.
 /// </summary>
 private void DestinationButton_Click(object sender, EventArgs e)
 {
     if (destinationFolderBrowserDialog.ShowDialog() == DialogResult.OK)
     {
         destinationTextBox.Text = destinationFolderBrowserDialog.SelectedPath = Unc.TranslatePath(destinationFolderBrowserDialog.SelectedPath);
     }
 }