|
@@ -44,6 +44,7 @@ type BackupTask struct {
|
|
|
JobName string //The name used by the scheduler for executing this config
|
|
|
CycleCounter int64 //The number of backup executed in the background
|
|
|
LastCycleTime int64 //The execution time of the last cycle
|
|
|
+ Enabled bool //Check if the task is enabled. Will not execute if this is set to false
|
|
|
DiskUID string //The UID of the target fsandlr
|
|
|
DiskPath string //The mount point for the disk
|
|
|
ParentUID string //Parent virtal disk UUID
|
|
@@ -56,14 +57,15 @@ type BackupTask struct {
|
|
|
type RestorableFile struct {
|
|
|
Filename string //Filename of this restorable object
|
|
|
RelpathOnDisk string //Relative path of this file to the root
|
|
|
- Deleteime int64 //Delete remaining time
|
|
|
+ BackupDiskUID string //The UID of disk that is hold the backup of this file
|
|
|
+ RemainingTime int64 //Remaining time till auto remove
|
|
|
+ Deleteime int64 //Delete time
|
|
|
}
|
|
|
|
|
|
//The restorable report
|
|
|
type RestorableReport struct {
|
|
|
- ParentUID string //The Disk ID to be restored to
|
|
|
- DiskUID string //The Backup disk UID
|
|
|
- RestorableFiles []RestorableFile //A list of restorable files
|
|
|
+ ParentUID string //The Disk ID to be restored to
|
|
|
+ RestorableFiles []*RestorableFile //A list of restorable files
|
|
|
}
|
|
|
|
|
|
var (
|
|
@@ -88,7 +90,9 @@ func NewHyperBackupManager() *Manager {
|
|
|
select {
|
|
|
case <-ticker.C:
|
|
|
for _, task := range newManager.Tasks {
|
|
|
- task.HandleBackupProcess()
|
|
|
+ if task.Enabled == true {
|
|
|
+ task.HandleBackupProcess()
|
|
|
+ }
|
|
|
}
|
|
|
case <-stopper:
|
|
|
return
|
|
@@ -111,15 +115,33 @@ func (m *Manager) AddTask(newtask *BackupTask) error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Add task to list
|
|
|
m.Tasks = append(m.Tasks, newtask)
|
|
|
|
|
|
+ //Start the task
|
|
|
+ m.StartTask(newtask.JobName)
|
|
|
+
|
|
|
log.Println(">>>> [Debug] New Backup Tasks added: ", newtask.JobName, newtask)
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (m *Manager) StopTask(jobname string) error {
|
|
|
- return nil
|
|
|
+//Start a given task given name
|
|
|
+func (m *Manager) StartTask(jobname string) {
|
|
|
+ for _, task := range m.Tasks {
|
|
|
+ if task.JobName == jobname {
|
|
|
+ task.Enabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//Stop a given task given its job name
|
|
|
+func (m *Manager) StopTask(jobname string) {
|
|
|
+ for _, task := range m.Tasks {
|
|
|
+ if task.JobName == jobname {
|
|
|
+ task.Enabled = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Stop all managed handlers
|
|
@@ -335,8 +357,45 @@ func HandleRestore(parentDiskID string, restoreDiskID string, targetFileRelpath
|
|
|
}
|
|
|
|
|
|
//List the file that is restorable from the given disk
|
|
|
-func (m *Manager) ListRestorable(parentDiskID string) RestorableReport {
|
|
|
- return RestorableReport{}
|
|
|
+func (m *Manager) ListRestorable(parentDiskID string) (RestorableReport, error) {
|
|
|
+ //List all the backup process that is mirroring this parent disk
|
|
|
+ tasks := m.getTaskByParentDiskID(parentDiskID)
|
|
|
+ if len(tasks) == 0 {
|
|
|
+ return RestorableReport{}, errors.New("No backup root found for this " + parentDiskID + ":/ virtual root.")
|
|
|
+ }
|
|
|
+
|
|
|
+ diffFiles := []*RestorableFile{}
|
|
|
+
|
|
|
+ //Extract all comparasion
|
|
|
+ for _, task := range tasks {
|
|
|
+ restorableFiles, err := task.compareRootPaths()
|
|
|
+ if err != nil {
|
|
|
+ //Unable to list restorable. SKip this
|
|
|
+ } else {
|
|
|
+ for _, restorable := range restorableFiles {
|
|
|
+ diffFiles = append(diffFiles, restorable)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Create a Restorable Report
|
|
|
+ thisReport := RestorableReport{
|
|
|
+ ParentUID: parentDiskID,
|
|
|
+ RestorableFiles: diffFiles,
|
|
|
+ }
|
|
|
+
|
|
|
+ return thisReport, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (m *Manager) getTaskByParentDiskID(parentDiskID string) []*BackupTask {
|
|
|
+ possibleTask := []*BackupTask{}
|
|
|
+ for _, task := range m.Tasks {
|
|
|
+ if task.ParentUID == parentDiskID {
|
|
|
+ //This task parent is the target disk. push this to list
|
|
|
+ possibleTask = append(possibleTask, task)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return possibleTask
|
|
|
}
|
|
|
|
|
|
//Get and return the file hash for a file
|