Skip to content

Commit

Permalink
feat: keep the working snapshot for resuming
Browse files Browse the repository at this point in the history
  • Loading branch information
idawnlight committed Oct 25, 2023
1 parent 12cb6ea commit 6bc882b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal

// Version of the program
const Version string = "0.8.0-seu"
const Version string = "0.8.1-seu"
32 changes: 12 additions & 20 deletions worker/btrfs_snapshot_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type providerBtrfsSnapshotConfig struct {
mirrorServeDir string
// created rw subvolume for syncing, and should only exist when syncing
// case: succeeded => create a new ro snapshot (@[timestamp]), update the soft link and delete the previous one
// case: failed => delete the rw subvolume
// case: failed => ~~delete the rw subvolume~~ keep it to resume progress
mirrorWorkingDir string
// store all ro snapshots
mirrorSnapshotDir string
Expand Down Expand Up @@ -189,30 +189,16 @@ func newBtrfsSnapshotHook(provider mirrorProvider, config providerBtrfsSnapshotC
}
}

// create a new rw Btrfs working snapshot before first attempt
func (h *btrfsSnapshotHook) preJob() error {
return nil
}

// create a new rw Btrfs working snapshot for every sync attempt
func (h *btrfsSnapshotHook) preExec() error {
workingDir := h.config.mirrorWorkingDir
latestSnapshot, err := h.config.LatestSnapshotPath()
if err != nil {
return err
}

if _, err := os.Stat(workingDir); err == nil {
// if is, err := btrfs.IsSubVolume(workingDir); err != nil {
// return err
// } else if !is {
// return fmt.Errorf("workingDir %s exists but isn't a Btrfs subvolume", workingDir)
// } else {
// logger.Noticef("Btrfs working snapshot %s exists, removing", workingDir)
// if err := tryDeleteSubvolume(workingDir); err != nil {
// return err
// }
// }
logger.Noticef("Btrfs working snapshot %s exists", workingDir)
logger.Noticef("Btrfs working snapshot %s exists, resuming", workingDir)
} else if os.IsNotExist(err) {
// create rw temp snapshot
if err := tryCreateSnapshot(latestSnapshot, workingDir, false); err != nil {
Expand All @@ -228,6 +214,10 @@ func (h *btrfsSnapshotHook) preExec() error {
return nil
}

func (h *btrfsSnapshotHook) preExec() error {
return nil
}

func (h *btrfsSnapshotHook) postExec() error {
return nil
}
Expand Down Expand Up @@ -289,9 +279,11 @@ func (h *btrfsSnapshotHook) postSuccess() error {
return nil
}

// delete working snapshot
func (h *btrfsSnapshotHook) postFail() error {
workingDir := h.config.mirrorWorkingDir
// workingDir := h.config.mirrorWorkingDir
//
// return tryDeleteSubvolume(workingDir)

return tryDeleteSubvolume(workingDir)
// Just keep the working snapshot to resume progress, rsync will handle it
return nil
}

0 comments on commit 6bc882b

Please sign in to comment.