|
@@ -167,8 +167,6 @@ func (m *Manager) Close() error {
|
|
|
|
|
|
//Main handler function for hybrid backup
|
|
|
func (backupConfig *BackupTask) HandleBackupProcess() (string, error) {
|
|
|
- log.Println(">>>>>> [Debug] Running backup process: ", backupConfig)
|
|
|
-
|
|
|
//Check if the target disk is writable and mounted
|
|
|
if fileExists(filepath.Join(backupConfig.ParentPath, "aofs.db")) && fileExists(filepath.Join(backupConfig.ParentPath, "aofs.db.lock")) {
|
|
|
//This parent filesystem is mounted
|
|
@@ -194,12 +192,14 @@ func (backupConfig *BackupTask) HandleBackupProcess() (string, error) {
|
|
|
deepBackup = false
|
|
|
backupConfig.LastCycleTime = time.Now().Unix()
|
|
|
}
|
|
|
+ log.Println("[HybridBackup] Basic backup executed: " + backupConfig.ParentUID + ":/ -> " + backupConfig.DiskUID + ":/")
|
|
|
return executeBackup(backupConfig, deepBackup)
|
|
|
} else if backupConfig.Mode == "nightly" {
|
|
|
if time.Now().Unix()-backupConfig.LastCycleTime >= 86400 {
|
|
|
//24 hours from last backup. Execute deep backup now
|
|
|
executeBackup(backupConfig, true)
|
|
|
backupConfig.LastCycleTime = time.Now().Unix()
|
|
|
+ log.Println("[HybridBackup] Executing nightly backup: " + backupConfig.ParentUID + ":/ -> " + backupConfig.DiskUID + ":/")
|
|
|
}
|
|
|
|
|
|
} else if backupConfig.Mode == "version" {
|
|
@@ -208,6 +208,7 @@ func (backupConfig *BackupTask) HandleBackupProcess() (string, error) {
|
|
|
//Scheduled backup or initial backup
|
|
|
executeVersionBackup(backupConfig)
|
|
|
backupConfig.LastCycleTime = time.Now().Unix()
|
|
|
+ log.Println("[HybridBackup] Executing backup schedule: " + backupConfig.ParentUID + ":/ -> " + backupConfig.DiskUID + ":/")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -229,7 +230,7 @@ func (m *Manager) GetParentDiskIDByRestoreDiskID(restoreDiskID string) (string,
|
|
|
}
|
|
|
|
|
|
//Restore accidentailly removed file from backup
|
|
|
-func (m *Manager) HandleRestore(restoreDiskID string, targetFileRelpath string) error {
|
|
|
+func (m *Manager) HandleRestore(restoreDiskID string, targetFileRelpath string, username *string) error {
|
|
|
//Get the backup task from backup disk id
|
|
|
backupTask := m.getTaskByBackupDiskID(restoreDiskID)
|
|
|
if backupTask == nil {
|
|
@@ -242,31 +243,39 @@ func (m *Manager) HandleRestore(restoreDiskID string, targetFileRelpath string)
|
|
|
restoreSource := filepath.Join(backupTask.DiskPath, targetFileRelpath)
|
|
|
if backupTask.Mode == "basic" || backupTask.Mode == "nightly" {
|
|
|
restoreSource = filepath.Join(backupTask.DiskPath, "/backup/", targetFileRelpath)
|
|
|
- } else if backupTask.Mode == "version" {
|
|
|
- restoreSource = filepath.Join(backupTask.DiskPath, "/versions/", targetFileRelpath)
|
|
|
- }
|
|
|
+ restoreTarget := filepath.Join(backupTask.ParentPath, targetFileRelpath)
|
|
|
|
|
|
- restoreTarget := filepath.Join(backupTask.ParentPath, targetFileRelpath)
|
|
|
+ if !fileExists(restoreSource) {
|
|
|
+ //Restore source not exists
|
|
|
+ return errors.New("Restore source file not exists")
|
|
|
+ }
|
|
|
|
|
|
- if !fileExists(restoreSource) {
|
|
|
- //Restore source not exists
|
|
|
- return errors.New("Restore source file not exists")
|
|
|
- }
|
|
|
+ if fileExists(restoreTarget) {
|
|
|
+ //Restore target already exists.
|
|
|
+ return errors.New("Restore target already exists. Cannot overwrite.")
|
|
|
+ }
|
|
|
|
|
|
- if fileExists(restoreTarget) {
|
|
|
- //Restore target already exists.
|
|
|
- return errors.New("Restore target already exists. Cannot overwrite.")
|
|
|
- }
|
|
|
+ //Check if the restore target parent folder exists. If not, create it
|
|
|
+ if !fileExists(filepath.Dir(restoreTarget)) {
|
|
|
+ os.MkdirAll(filepath.Dir(restoreTarget), 0755)
|
|
|
+ }
|
|
|
|
|
|
- //Check if the restore target parent folder exists. If not, create it
|
|
|
- if !fileExists(filepath.Dir(restoreTarget)) {
|
|
|
- os.MkdirAll(filepath.Dir(restoreTarget), 0755)
|
|
|
- }
|
|
|
+ //Ready to move it back
|
|
|
+ err := BufferedLargeFileCopy(restoreSource, restoreTarget, 4086)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("Restore failed: " + err.Error())
|
|
|
+ }
|
|
|
+ } else if backupTask.Mode == "version" {
|
|
|
+ //Check if username is set
|
|
|
+ if username == nil {
|
|
|
+ return errors.New("Snapshot mode backup require username to restore")
|
|
|
+ }
|
|
|
|
|
|
- //Ready to move it back
|
|
|
- err := BufferedLargeFileCopy(restoreSource, restoreTarget, 4086)
|
|
|
- if err != nil {
|
|
|
- return errors.New("Restore failed: " + err.Error())
|
|
|
+ //Restore the snapshot
|
|
|
+ err := restoreSnapshotByName(backupTask, targetFileRelpath, username)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("Restore failed: " + err.Error())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Restore completed
|