|
@@ -34,7 +34,11 @@ import (
|
|
|
- If you need any function from the file system, copy and paste it in this module
|
|
|
*/
|
|
|
|
|
|
-type BackupConfig struct {
|
|
|
+type Manager struct {
|
|
|
+ Tasks []*BackupTask
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
@@ -46,11 +50,93 @@ type BackupConfig struct {
|
|
|
Mode string //Backup mode
|
|
|
}
|
|
|
|
|
|
-func executeBackup(backupConfig *BackupConfig, deepBackup bool) (string, error) {
|
|
|
+//A file in the backup drive that is restorable
|
|
|
+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
|
|
|
+}
|
|
|
+
|
|
|
+//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
|
|
|
+}
|
|
|
+
|
|
|
+func NewHyperBackupManager() *Manager {
|
|
|
+ return &Manager{
|
|
|
+ Tasks: []*BackupTask{},
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (m *Manager) AddTask(newtask *BackupTask) error {
|
|
|
+ log.Println(">>>> [Debug] New Backup Tasks added: ", newtask)
|
|
|
+
|
|
|
+ /*for _, thisHandler := range fsHandlers {
|
|
|
+
|
|
|
+ if thisHandler.Hierarchy == "backup" {
|
|
|
+ //This is a backup drive. Generate it handler
|
|
|
+ backupConfig := thisHandler.HierarchyConfig.(hybridBackup.BackupTask)
|
|
|
+
|
|
|
+ //Get its parent mount point for backup
|
|
|
+ parentFileSystemHandler, err := GetFsHandlerByUUID(backupConfig.ParentUID)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Virtual Root with UUID: " + backupConfig.ParentUID + " not loaded. Unable to start backup process.")
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ backupConfig.JobName = "backup-daemon [" + thisHandler.UUID + "]"
|
|
|
+ backupConfig.ParentPath = parentFileSystemHandler.Path
|
|
|
+ backupConfig.CycleCounter = 1
|
|
|
+
|
|
|
+ //Debug backup execution
|
|
|
+ hybridBackup.HandleBackupProcess(&backupConfig)
|
|
|
+
|
|
|
+ //Remove the previous job if it exists
|
|
|
+ if systemScheduler.JobExists(backupConfig.JobName) {
|
|
|
+ systemScheduler.RemoveJobFromScheduleList(backupConfig.JobName)
|
|
|
+ }
|
|
|
+
|
|
|
+ //Create a scheudler for this disk
|
|
|
+ systemScheduler.CreateNewScheduledFunctionJob(backupConfig.JobName,
|
|
|
+ "Backup daemon from "+backupConfig.ParentUID+":/ to "+backupConfig.DiskUID+":/",
|
|
|
+ 60,
|
|
|
+ func() (string, error) {
|
|
|
+ return hybridBackup.HandleBackupProcess(&backupConfig)
|
|
|
+ },
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ }*/
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func executeBackup(backupConfig *BackupTask, deepBackup bool) (string, error) {
|
|
|
copiedFileList := []string{}
|
|
|
|
|
|
rootPath := filepath.ToSlash(filepath.Clean(backupConfig.ParentPath))
|
|
|
|
|
|
+ //Check if the backup parent root is identical / within backup disk
|
|
|
+ parentRootAbs, err := filepath.Abs(backupConfig.ParentPath)
|
|
|
+ if err != nil {
|
|
|
+ return "", errors.New("Unable to resolve parent disk path")
|
|
|
+ }
|
|
|
+
|
|
|
+ backupRootAbs, err := filepath.Abs(backupConfig.DiskPath)
|
|
|
+ if err != nil {
|
|
|
+ return "", errors.New("Unable to resolve backup disk path")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(parentRootAbs) >= len(backupRootAbs) {
|
|
|
+ if parentRootAbs[:len(backupRootAbs)] == backupRootAbs {
|
|
|
+ //parent root is within backup root. Raise configuration error
|
|
|
+ log.Println("*HyperBackup* Invalid backup cycle: Parent drive is located inside backup drive")
|
|
|
+ return "", errors.New("Configuration Error. Skipping backup cycle.")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//Add file cycles
|
|
|
fastWalk(rootPath, func(filename string) error {
|
|
|
if filepath.Base(filename) == "aofs.db" || filepath.Base(filename) == "aofs.db.lock" {
|
|
@@ -173,7 +259,7 @@ func executeBackup(backupConfig *BackupConfig, deepBackup bool) (string, error)
|
|
|
}
|
|
|
|
|
|
//Main handler function for hybrid backup
|
|
|
-func HandleBackupProcess(backupConfig *BackupConfig) (string, error) {
|
|
|
+func HandleBackupProcess(backupConfig *BackupTask) (string, error) {
|
|
|
log.Println(">>>>>> [Debug] Running backup process: ", backupConfig)
|
|
|
|
|
|
//Check if the target disk is writable and mounted
|
|
@@ -223,13 +309,13 @@ func HandleBackupProcess(backupConfig *BackupConfig) (string, error) {
|
|
|
}
|
|
|
|
|
|
//Restore accidentailly removed file from backup
|
|
|
-func HandleRestore(backupConfig *BackupConfig, targetFile string) error {
|
|
|
+func HandleRestore(backupConfig *BackupTask, targetFile string) error {
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//List the file that is restorable from the given disk
|
|
|
-func ListRestorable(ackupConfig *BackupConfig) {
|
|
|
+func ListRestorable(backupConfig *BackupTask) {
|
|
|
|
|
|
}
|
|
|
|