Ejemplo n.º 1
0
        FileSystemWatcherWorkerTask(BackupProfileData profile, long wakeupIntervalSec)
        {
            m_Profile = profile;
            m_Logger  = profile.Logger;

            WorkerReportsProgress      = true;
            WorkerSupportsCancellation = true;

            DoWork += (sender, e) =>
            {
                //var watchList = profile.BackupWatcherItemList;
                try
                {
                    //watchList.Clear();

                    foreach (var backupItem in profile.BackupFolderList)
                    {
                        m_Logger.Writeln($"Starting File System Watcher: {backupItem.Path}");
                        try
                        {
                            new FileSystemWatcerItemManager(m_Profile).RunWatcher(backupItem.Path);
                        }
                        catch (FileNotFoundException)
                        {
                            m_Logger.Writeln($"***Warning: Backup item not available: {backupItem.Path}");
                        }
                    }
                }
                catch (TaskCanceledException ex)
                {
                    m_Logger.Writeln($"File System Watcher exception: {ex.Message}");
                    Trace.WriteLine($"File System Watcher exception: {ex.Message}");
                    e.Result = $"Full Backup exception: {ex.Message}";
                    throw (ex);
                }
                finally
                {
                }
            };

            m_FileSystemWatcherBackupTimer = new FileSystemProfileBackupWatcherTimer()
            {
                Profile   = profile,
                Interval  = wakeupIntervalSec,
                AutoReset = true,
                Enabled   = profile.IsWatchFileSystem,
            };

            m_FileSystemWatcherBackupTimer.Elapsed += BackupTaskManager.OnFileSystemWatcherBackupTimerStartBackup;
        }
Ejemplo n.º 2
0
        private void BackupTaskRunWorkerCompletedEvent(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled == true)
            {
                m_Logger.Writeln($"Backup task canceled");
            }
            else if (e.Error != null)
            {
                m_Logger.Writeln($"***Backup task ended with error:\n{e.Error.Message}");
            }
            else
            {
                m_Logger.Writeln($"Backup task ended normally");
            }

            lock (this)
            {
            }

            BackupTaskManager.Instance.CompleteAndStartNextBackup(this);
        }
Ejemplo n.º 3
0
 protected void CopyUpdatedFile(string sourcePath, string targetPath, bool overwrite = false)
 {
     m_Logger.Writeln($"File UpdatedL: {sourcePath}");
     m_IStorage.CopyFile(sourcePath, targetPath, overwrite);
 }
Ejemplo n.º 4
0
        public BackupProcessWorkerTask(BackupProfileData profile, bool bFullBackupScan)
        {
            m_Profile         = profile;
            m_Logger          = profile.Logger;
            m_bFullBackupScan = bFullBackupScan;

            WorkerReportsProgress      = true;
            WorkerSupportsCancellation = true;

            DoWork += (sender, e) =>
            {
                m_MaxActiveCPU = Properties.General.Default.MaxCPUOnBusy;
                m_MaxIdleCPU   = Properties.General.Default.MaxCPUOnAway;

                m_ProgressBar = GenericStatusBarView.NewInstance;
                profile.IsBackupWorkerBusy = true;
                //                RunWorkerCompleted += new RunWorkerCompletedEventHandler(BackupTaskRunWorkerCompletedEvent);
                ProgressChanged    += BackupTaskRunWorkerProgressChangedEvent;
                RunWorkerCompleted += BackupTaskRunWorkerCompletedEvent;

                //profile.IsBackupWorkerBusy = true;
                m_ProgressBar.UpdateProgressBar("Backup starting...", 0);
                var startTime = DateTime.Now;

                m_Logger.Writeln($"-------------------------------------------------");
                try
                {
                    switch (profile.BackupType)
                    {
                    case BackupTypeEnum.Differential:
                        if (bFullBackupScan)
                        {
                            m_Logger.Writeln($"Starting a Full Deep Differential backup");
                            m_BackupManager = new DifferentialBackup(profile, m_ProgressBar);
                        }
                        else
                        {
                            m_Logger.Writeln($"Starting a Differential watcher backup");
                            m_BackupManager = new DifferentialWatcherBackup(profile, m_ProgressBar);
                        }
                        break;

                    case BackupTypeEnum.Incremental:
                        if (bFullBackupScan)
                        {
                            m_Logger.Writeln($"Starting a Full Deep Incremental backup");
                            m_BackupManager = new IncrementalFullBackup(profile, m_ProgressBar);
                        }
                        else
                        {
                            m_Logger.Writeln($"Starting Incremental watcher backup");
                            m_BackupManager = new IncrementalFullWatcherBackup(profile, m_ProgressBar);
                        }
                        break;

                    case BackupTypeEnum.Snapshot:
                        m_Logger.Writeln($"Starting a Snapshot backup");
                        m_BackupManager = new SnapshotBackup(profile, m_ProgressBar);
                        break;

                    default:
                        throw new ArgumentNullException("Unknown backup type in BackupWorker");
                    }

                    m_BackupManager.Init();
                    m_BackupManager.ProcessBackup();
                    m_BackupManager.Done();

                    m_Profile.RefreshProfileProperties();
                }
                catch (TaskCanceledException ex)
                {
                    m_Logger.Writeln($"Backup exception: {ex.Message}");
                    m_ProgressBar.UpdateProgressBar("Completed with Errors");
                    Trace.WriteLine($"Full Backup exception: {ex.Message}");
                    e.Result = $"Full Backup exception: {ex.Message}";
                    throw (ex);
                }
                finally
                {
                    if (CancellationPending)
                    {
                        e.Cancel = true;
                    }

                    m_Logger.Writeln($"Backup completed, execution time: {DateTime.Now - startTime}");
                    m_ProgressBar.Release();
                    m_ProgressBar   = null;
                    m_BackupManager = null;
                }
            };
        }