示例#1
0
        public void TestSchedulesWeekly()
        {
            var job = new ArchiveJob
            {
                Active = true,
            };
            job.Schedules[0] = new JobSchedule
            {
                ScheduleType = JobScheduleType.Weekly,
                Weekly =
                {
                    Every = 3,
                    RunAt = new HourMinute {Hour = 10, Minute = 30},
                    JobDays = JobDays.Tuesday | JobDays.Thursday | JobDays.Sunday
                }
            };

            var p = new CloudBackup.Backup.Scheduler.ScheduleJob(job);

            var t1 = p.ComputeNextRuntime(
                new DateTime(2014, 1, 1, 9, 30, 0)
                );
            Assert.IsTrue(t1 == new DateTime(2014, 1, 2, 10, 30, 0));
            t1 = p.ComputeNextRuntime(new DateTime(2014, 1, 8, 11, 30, 0));
            Assert.IsTrue(t1 == new DateTime(2014, 1, 14, 10, 30, 0));
            t1 = p.ComputeNextRuntime(new DateTime(2014, 1, 25, 23, 30, 0));
            Assert.IsTrue(t1 == new DateTime(2014, 1, 26, 10, 30, 0));
        }
示例#2
0
        public void TestSchedulesMonthly()
        {
            var job = new ArchiveJob
            {
                Active = true,
            };
            job.Schedules[0] = new JobSchedule
            {
                ScheduleType = JobScheduleType.Monthly,
                Monthly =
                {
                    Every = 3,
                    RunAt = new HourMinute { Hour = 10, Minute = 30 },
                    RelativeTo = JobRelativeTo.FirstSundayOfTheMonth,
                    DayOffset = 3
                }
            };

            var p = new CloudBackup.Backup.Scheduler.ScheduleJob(job);

            var t1 = p.ComputeNextRuntime(
                new DateTime(2014, 1, 1, 9, 30, 0)
                );
            Assert.IsTrue(t1 == new DateTime(2014, 1, 8, 10, 30, 0));
            t1 = p.ComputeNextRuntime(new DateTime(2014, 2, 14, 23, 30, 0));
            Assert.IsTrue(t1 == new DateTime(2014, 4, 9, 10, 30, 0));
        }
示例#3
0
        public void SaveSchedule()
        {
            var schedule = new ArchiveJob();
            schedule.Schedules.Add(new JobSchedule{ScheduleType = JobScheduleType.Daily});

            string result;
            var serializer = new XmlSerializer(typeof (ArchiveJob));
            using (TextWriter writer = new StringWriter())
            {
                serializer.Serialize(writer,schedule);
                result= writer.ToString();
            }

            ArchiveJob decSchedule;
            serializer = new XmlSerializer(typeof(ArchiveJob));
            using (TextReader reader = new StringReader(result))
            {
                decSchedule = (ArchiveJob) serializer.Deserialize(reader);
            }
        }
示例#4
0
        Process(ArchiveJob job, bool forceFullBackup,string reason)
        {
            _backupReason = reason;
            _forceFullBackup = forceFullBackup;
            _job = job;
            _now = DateTime.Now;
            var jid = job.JobUID.Value;
            _id = _now.ToUniversalTime().Ticks;
            _fileName = string.Format("BACKUP_{0:00000}_{8}_{1:0000}{2:00}{3:00}_{4:00}{5:00}{6:00}_{7:000}.{9}.zip", jid, _now.Year, _now.Month,
                _now.Day, _now.Hour,_now.Minute,_now.Second,
                _now.Millisecond,
                forceFullBackup?"FULL":"INCR",
                Environment.MachineName);

            _report = new StringBuilder();
            _report.AppendLine("Target filename: " + _fileName);

            _proxy = Program.Database.CreateSnapProxy();
            _proxy.CreateSnapshotFile(_id, jid, _fileName, _id);
            _proxy.ClearSeenFlags(jid);
        }
示例#5
0
 void ReloadJobList()
 {
     lbAllSchedule.Items.Clear();
     foreach (var job in _serverLink.GetJobs())
     {
         lbAllSchedule.Items.Add(job.Name);
     }
     if (lbAllSchedule.Items.Count == 0)
     {
         _archiveJob = null;
         SyncGuiWithArchive();
     }
     else
     {
         lbAllSchedule.SelectedIndex = 0;
     }
 }
示例#6
0
        private void lbAllSchedule_SelectedIndexChanged(object sender, EventArgs e)
        {
            var active = lbAllSchedule.SelectedItem as string;
            _archiveJob = string.IsNullOrEmpty(active) ? null : _serverLink.LoadArchiveJob(active);
            _schedule = null;

            if (_archiveJob != null)
            {
                //btnDelSchedule.Enabled = true;
                btnDelArchive.Enabled = true;
            }
            SyncGuiWithArchive();
        }
示例#7
0
 private void btnNewArchive_Click(object sender, EventArgs e)
 {
     lbAllSchedule.SelectedItem = null;
     _suspendJobCheckEvents = true;
     _archiveJob = new ArchiveJob();
     _schedule = null;
     btnDelSchedule.Enabled = false;
     lbAllSchedule.SelectedItem = null;
     _suspendJobCheckEvents = false;
     SyncGuiWithArchive();
 }
示例#8
0
        public int SaveOrUpdateArchiveJob(ArchiveJob job)
        {
            log.InfoFormat("Saving/Updating job [{0}]:[{1}] {2}",job.JobUID,job.UniqueJobName,job);
            if (!job.JobUID.HasValue)
            {
                job.JobUID = Program.Database.GenerateJobUid();
            }

            var xmlSchedule = ArchiveJob.SaveSchedule(job);
            log.InfoFormat("Schedule : {0}", job.ToString());

            Program.Database.JobProxy.InsertSchedule(
                job.JobUID.Value,
                job.UniqueJobName,
                xmlSchedule,
                job.Active
            );

            Program.Scheduler.ReLoadSchedule();

               return job.JobUID.Value;
        }
示例#9
0
 public ScheduleJob(ArchiveJob job)
 {
     _job = job;
 }
示例#10
0
 public ScheduleJob(Database.ScheduleRow rawSchedule)
 {
     _job = ArchiveJob.LoadSchedule(rawSchedule.Description);
     _job.JobUID = rawSchedule.Uid;
     _job.UniqueJobName = rawSchedule.Name;
     _job.Active = rawSchedule.Active;
 }
示例#11
0
 public static string SaveSchedule(ArchiveJob job)
 {
     var serializer = new XmlSerializer(typeof(ArchiveJob));
     using (TextWriter writer = new StringWriter())
     {
         serializer.Serialize(writer, job);
         return writer.ToString();
     }
 }
示例#12
0
        public static void RunBackup(ArchiveJob job,bool forceFullBackup, string reason)
        {
            log.InfoFormat("Starting backup of [{0}]", job.JobRootPath);

            using (var process = new Process(job, forceFullBackup, reason))
            {
                try
                {
                    process.BuildConnectBackend();

                    var engine = new Engine { RootPath = job.JobRootPath };
                    using (var backup = engine.CreateBackup())
                    {
                        //- First create a snapshot
                        process.BuildSnapshot(backup);

                        //- Publish ZIP file
                        process.PublishZipFile(backup);
                    }

                    log.InfoFormat("Process completed - Commit Transaction");
                    process.CommitTransaction();

                    // Post process
                    if (job.JobTarget.ManageTargetFiles)
                    {
                        process.ClearUnneededFiles();
                    }
                }
                catch(Exception ex)
                {
                    process._proxy.Transaction.Rollback();
                    process._proxy = null;

                    log.Error("Process failed ! - Rollback Transaction", ex);
                    process._report.AppendLine("** FAILED ** Exception: " + ex);

                    var proxy = Program.Database.CreateSnapProxy();
                    proxy.BackupReport(job.JobUID.Value, process._now.Ticks, false,reason, process._report.ToString());
                    proxy.Transaction.Commit();
                }
            }
        }
示例#13
0
 public ManifestDocument(ArchiveJob job,long jobId)
 {
     _manifest = new XmlDocument();
     _manifest.LoadXml(string.Format("<manifest id=\"{0}\" jid=\"{1}\" />", jobId, job.JobUID.Value));
     _job = job;
     _tagsRoot = _manifest.CreateElement("tags");
     _manifest.DocumentElement.AppendChild(_tagsRoot);
 }