Kaynağa Gözat

Added status for backup task

tobychui 4 yıl önce
ebeveyn
işleme
7677e6f4db

+ 2 - 0
backup.go

@@ -77,6 +77,7 @@ func backup_listAllBackupDisk(w http.ResponseWriter, r *http.Request) {
 		BackupMode          string //The backup mode of the drive
 		LastBackupCycleTime int64  //Last backup timestamp
 		BackupCycleCount    int64  //How many backup cycle has proceeded since the system startup
+		Error               bool   //If there are error occured in the last cycle
 	}
 
 	backupDrives := []*backupDrive{}
@@ -98,6 +99,7 @@ func backup_listAllBackupDisk(w http.ResponseWriter, r *http.Request) {
 			BackupMode:          task.Mode,
 			LastBackupCycleTime: task.LastCycleTime,
 			BackupCycleCount:    task.CycleCounter,
+			Error:               task.PanicStopped,
 		})
 	}
 

+ 5 - 0
mod/disk/hybridBackup/basicBackup.go

@@ -25,11 +25,13 @@ func executeBackup(backupConfig *BackupTask, deepBackup bool) (string, error) {
 	//Check if the backup parent root is identical / within backup disk
 	parentRootAbs, err := filepath.Abs(backupConfig.ParentPath)
 	if err != nil {
+		backupConfig.PanicStopped = true
 		return "", errors.New("Unable to resolve parent disk path")
 	}
 
 	backupRootAbs, err := filepath.Abs(filepath.Join(backupConfig.DiskPath, "/backup/"))
 	if err != nil {
+		backupConfig.PanicStopped = true
 		return "", errors.New("Unable to resolve backup disk path")
 	}
 
@@ -37,10 +39,13 @@ func executeBackup(backupConfig *BackupTask, deepBackup bool) (string, error) {
 		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")
+			backupConfig.PanicStopped = true
 			return "", errors.New("Configuration Error. Skipping backup cycle.")
 		}
 	}
 
+	backupConfig.PanicStopped = false
+
 	//Add file cycles
 	//log.Println("[Debug] Cycle 1: Adding files")
 	fastWalk(rootPath, func(filename string) error {

+ 1 - 0
mod/disk/hybridBackup/hybridBackup.go

@@ -55,6 +55,7 @@ type BackupTask struct {
 	DeleteFileMarkers map[string]int64   //Markers for those files delete pending, [file path (relative)] time
 	Database          *database.Database //The database for storing requried data
 	Mode              string             //Backup mode
+	PanicStopped      bool               //If the backup process has been stopped due to panic situationc
 }
 
 //A snapshot summary

+ 9 - 4
mod/disk/hybridBackup/versionBackup.go

@@ -20,22 +20,27 @@ func executeVersionBackup(backupConfig *BackupTask) (string, error) {
 	//Check if the backup parent root is identical / within backup disk
 	parentRootAbs, err := filepath.Abs(backupConfig.ParentPath)
 	if err != nil {
+		backupConfig.PanicStopped = true
 		return "", errors.New("Unable to resolve parent disk path")
 	}
 
 	backupRootAbs, err := filepath.Abs(filepath.Join(backupConfig.DiskPath, "/version/"))
 	if err != nil {
+		backupConfig.PanicStopped = true
 		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")
+			log.Println("[HyperBackup] Invalid backup cycle: Parent drive is located inside backup drive")
+			backupConfig.PanicStopped = true
 			return "", errors.New("Configuration Error. Skipping backup cycle.")
 		}
 	}
 
+	backupConfig.PanicStopped = false
+
 	todayFolderName := time.Now().Format("2006-01-02")
 	previousSnapshotExists := true
 	previousSnapshotName, err := getPreviousSnapshotName(backupConfig, todayFolderName)
@@ -65,7 +70,7 @@ func executeVersionBackup(backupConfig *BackupTask) (string, error) {
 
 	//First pass: Check if there are any updated file from source and backup it to backup drive
 	fastWalk(parentRootAbs, func(filename string) error {
-		if filepath.Base(filename) == "aofs.db" || filepath.Base(filename) == "aofs.db.lock" {
+		if filepath.Ext(filename) == ".db" || filepath.Ext(filename) == ".lock" {
 			//Reserved filename, skipping
 			return nil
 		}
@@ -184,7 +189,7 @@ func executeVersionBackup(backupConfig *BackupTask) (string, error) {
 	//For case where the file is backed up in previous snapshot but now the file has been removed
 	if previousSnapshotExists {
 		fastWalk(previousSnapshotLocation, func(filename string) error {
-			if filepath.Base(filename) == "snapshot.datalink" {
+			if filepath.Ext(filename) == ".datalink" {
 				//System reserved file. Skip this
 				return nil
 			}
@@ -221,7 +226,7 @@ func executeVersionBackup(backupConfig *BackupTask) (string, error) {
 	//3rd pass: Check if there are anything (except file with .deleted) in today backup drive that didn't exists in the source drive
 	//For cases where the backup is applied to overwrite an eariler backup of the same day
 	fastWalk(snapshotLocation, func(filename string) error {
-		if filepath.Base(filename) == "aofs.db" || filepath.Base(filename) == "aofs.db.lock" {
+		if filepath.Ext(filename) == ".db" || filepath.Ext(filename) == ".lock" {
 			//Reserved filename, skipping
 			return nil
 		}

+ 1 - 0
mod/filesystem/filesystem.go

@@ -116,6 +116,7 @@ func NewFileSystemHandler(option FileSystemOption) (*FileSystemHandler, error) {
 				ParentUID:         option.Parentuid,
 				Mode:              option.BackupMode,
 				DeleteFileMarkers: map[string]int64{},
+				PanicStopped:      false,
 			}
 
 		}

+ 21 - 0
web/SystemAO/disk/backup/backups.html

@@ -4,6 +4,7 @@
 	<meta name="mobile-web-app-capable" content="yes">
 	<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
 	<meta charset="UTF-8">
+    <title>Backup Disk</title>
     <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
     <script src="../../script/jquery.min.js"></script>
 	<script src="../../script/semantic/semantic.min.js"></script>
@@ -16,6 +17,14 @@
             opacity: 0.5;
             pointer-events: none;
         }
+
+        td.green{
+            color: #5cad8b;
+        }
+
+        td.red{
+            color: #ff5c59;
+        }
     </style>
 </head>
 <body>
@@ -34,6 +43,7 @@
               <th>Mode</th>
               <th>Last Cycle Time</th>
               <th>Cycle Counter*</th>
+              <th>Status</th>
               <th>Action</th>
             </tr></thead>
             <tbody id="diskTable">
@@ -96,13 +106,24 @@
                     alert(data.error);
                 }else{
                     //Render the list
+                   
                     data.forEach(disk => {
+                        var statusText = `<i class="checkmark icon"></i> Normal`;
+                        var statusColor = "green";
+
+                        if (disk.Error == true){
+                            //Task execution error. 
+                            statusText = `<i class="exclamation triangle icon"></i> Stopped`;
+                            statusColor = "red";
+                        }
+
                         $("#diskTable").append(`<tr>
                             <td data-label=""><img class="ui avatar image" style="border-radius: 0px;" src="../../img/system/drive-backup.svg"> ${disk.DiskName} (${disk.DiskUID}:/)</td>
                             <td data-label=""><img class="ui avatar image" style="border-radius: 0px;" src="../../img/system/drive-virtual.svg"> ${disk.ParentName} (${disk.ParentUID}:/)</td>
                             <td data-label="">${disk.BackupMode}</td>
                             <td data-label="">${ao_module_utils.timeConverter(disk.LastBackupCycleTime)}</td>
                             <td data-label="">${disk.BackupCycleCount}</td>
+                            <td class="${statusColor}" data-label="">${statusText}</td>
                             <td data-label=""><button class="ui teal tiny button" onclick="openRestore('${disk.ParentUID}');">Restore Settings</button></td>
                         </tr> `);
                     });