private static void InitializeData(string setupPassword) { // node group with ID=0 mandatory, so it's the very first object to create NodeGroup defaultNG = new NodeGroup(); defaultNG.Description = "Default group"; defaultNG.Name = "Default"; new DAL.NodeGroupDAO().Save(defaultNG); Password adminP = new Password(); adminP.Value = setupPassword; adminP = PasswordManager.Add(adminP); User admin = new User(); admin.Login = "******"; admin.Name = "Superadmin user"; admin.Email = "*****@*****.**"; //admin.Roles.Add(new UserRole{Role = RoleEnum.SuperAdmin}); admin.IsEnabled = true; var adminRole = new UserRole(); adminRole.Role = RoleEnum.SuperAdmin; adminRole.GroupsInRole = new List <int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; admin.PasswordId = adminP.Id; admin.Roles = new List <UserRole>(); admin.Roles.Add(adminRole); admin = new DAL.UserDAO().Save(admin); BackupSet dummy = new BackupSet(); dummy.IsTemplate = true; dummy.Name = "Default BackupSet"; dummy.Operation = TaskOperation.Backup; dummy.Parallelism = new Parallelism() { Kind = ParallelismLevel.Disk, Value = 2 }; dummy.RetentionDays = 7; BasePath dp = new BasePath(); dp.Path = "*"; dp.Recursive = true; dp.Type = "FS:local"; dummy.BasePaths.Add(dp); dummy = new DAL.BackupSetDAO().Save(dummy); }
internal long StartImmediateTask(int bsId, User u, BackupLevel?level) { if (tokenSource.Token.IsCancellationRequested) { return(0); } BackupSet bs = new DAL.BackupSetDAO().GetById(bsId); if (bs != null && bs.Id >= 0) { Task manualTask = CreateTask(bs, TaskStartupType.Manual, u, level); StartTask(manualTask); return(manualTask.Id); } else { throw new Exception("Invalid Taskset id"); } }
private void Schedule(CancellationToken cancelToken) { while (!cancelToken.IsCancellationRequested) { if (isFirstStart) { int interruptedTasks = new DAL.TaskDAO().UpdateInterrupted(); Logger.Append("HUBRN", Severity.INFO, "Updated " + interruptedTasks + " previously interrupted task(s)."); Logger.Append("HUBRN", Severity.INFO, "Waiting 20s before starting to schedule tasks..."); Thread.Sleep(20000); isFirstStart = false; } Logger.Append("HUBRN", Severity.DEBUG, "Polling database for next BackupSets to run."); var nextBS = new List <BackupSet> (); try{ nextBS = new DAL.BackupSetDAO().GetNextToSchedule(1); } catch (Exception e) { Logger.Append("HUBRN", Severity.CRITICAL, "Cannot retrieve next tasks to schedule from DB : " + e.ToString()); } foreach (BackupSet bsn in nextBS) { CreateTask(bsn, TaskStartupType.Scheduled, null, null); } Logger.Append("HUBRN", Severity.DEBUG, "Added " + nextBS.Count + " Backup Sets to queue. Total queue size : " + TasksQueue.Count); for (int i = TasksQueue.Count - 1; i >= 0; i--) { Task task = TasksQueue.GetByIndex(i); //REACTIVER!!! //if(TimeSpan.Parse(bs.BackupTimes[0].Begin+":00") <= new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0)){ if (task.RunStatus == TaskRunningStatus.Done || task.RunStatus == TaskRunningStatus.Cancelled || task.RunStatus == TaskRunningStatus.Error) { Logger.Append("HUBRN", Severity.INFO, "Task " + task.Id + ", Backupset " + task.BackupSet.ToString() + " ended with status " + task.RunStatus + ", removing from queue."); task.EndDate = DateTime.Now; new DAL.TaskDAO().Complete(task); TasksQueue.RemoveAt(i); // TODO : remove this line, instead keep DEBUG one if (TaskEvent != null) { TaskEvent(task, null); } #if DEBUG #else TasksQueue.RemoveAt(i); #endif } else if (task.RunStatus == TaskRunningStatus.PendingStart) { task.Status = TaskStatus.Ok; try{ StartTask(task); task.RunStatus = TaskRunningStatus.Started; // wait 0.1 second before starting another task Thread.Sleep(100); } catch (OverQuotaException oqe) { Logger.Append("HUBRN", Severity.ERROR, "Could not start task #" + task.Id + " on client node #" + task.BackupSet.NodeId + " : " + oqe.Message); task.Status = TaskStatus.Error; task.RunStatus = TaskRunningStatus.Error; task.EndDate = DateTime.Now; task.CurrentAction = oqe.Message; task.AddLogEntry(new TaskLogEntry(task.Id) { Code = 830, Message1 = "", Message2 = "" }); } catch (UnreachableNodeException) { Logger.Append("HUBRN", Severity.ERROR, "Could not send task #" + task.Id + " to node #" + task.BackupSet.NodeId + ": Node is offline"); TimeSpan lateness = DateTime.Now.Subtract(task.StartDate); if (lateness >= new TimeSpan(0, maxLateness, 0)) { Logger.Append("HUBRN", Severity.ERROR, "Could not start task " + task.Id + " for client #" + task.BackupSet.NodeId + ", retry time expired. (lateness :" + lateness.Minutes + " minutes)"); task.Status = TaskStatus.Error; task.RunStatus = TaskRunningStatus.Error; task.EndDate = DateTime.Now; task.CurrentAction = "Retry time expired"; task.AddLogEntry(new TaskLogEntry(task.Id) { Code = 901, Message1 = "", Message2 = "" }); } else { int remainingRetry = new TimeSpan(0, maxLateness, 0).Subtract(lateness).Minutes; Logger.Append("HUBRN", Severity.WARNING, "Could not start task " + task.Id + " for client #" + task.BackupSet.NodeId + ", will retry during " + remainingRetry + " mn"); task.Status = TaskStatus.Warning; //TaskPublisher.Instance().Notify(task); task.AddLogEntry(new TaskLogEntry(task.Id) { Code = 901, Message1 = remainingRetry.ToString(), Message2 = "" }); task.CurrentAction = "Could not start operation, will retry during " + remainingRetry + " mn"; } } } } // end for Utils.SetProcInfo("Hub (" + TasksQueue.Count + " tasks)"); for (int i = 0; i < 60; i++) { if (!cancelToken.IsCancellationRequested) { Thread.Sleep(1000); } } } Logger.Append("HUBRN", Severity.INFO, "Scheduler stopped."); }