Skip to content

Commit

Permalink
Change snapshot source path from / to /System/Volumes/Data
Browse files Browse the repository at this point in the history
Also use a regex to extract the snapshot date from tmutil output.
  • Loading branch information
gilbertchen committed Oct 11, 2020
1 parent 7f834e8 commit 7c36311
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/duplicacy_shadowcopy_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"os"
"os/exec"
"regexp"
"strings"
"syscall"
"time"
)
Expand Down Expand Up @@ -77,19 +76,19 @@ func DeleteShadowCopy() {

err := exec.Command("/sbin/umount", "-f", snapshotPath).Run()
if err != nil {
LOG_ERROR("VSS_DELETE", "Error while unmounting snapshot")
LOG_WARN("VSS_DELETE", "Error while unmounting snapshot: %v", err)
return
}

err = exec.Command("tmutil", "deletelocalsnapshots", snapshotDate).Run()
if err != nil {
LOG_ERROR("VSS_DELETE", "Error while deleting local snapshot")
LOG_WARN("VSS_DELETE", "Error while deleting local snapshot: %v", err)
return
}

err = os.RemoveAll(snapshotPath)
if err != nil {
LOG_ERROR("VSS_DELETE", "Error while deleting temporary mount directory")
LOG_WARN("VSS_DELETE", "Error while deleting temporary mount directory: %v", err)
return
}

Expand Down Expand Up @@ -150,12 +149,13 @@ func CreateShadowCopy(top string, shadowCopy bool, timeoutInSeconds int) (shadow
return top
}

colonPos := strings.IndexByte(tmutilOutput, ':')
if colonPos < 0 {
snapshotDateRegex := regexp.MustCompile(`:\s+([0-9\-]+)`)
matched := snapshotDateRegex.FindStringSubmatch(tmutilOutput)
if matched == nil {
LOG_ERROR("VSS_CREATE", "Snapshot creation failed: %s", tmutilOutput)
return top
}
snapshotDate = strings.TrimSpace(tmutilOutput[colonPos+1:])
snapshotDate = matched[1]

tmutilOutput, err = CommandWithTimeout(timeoutInSeconds, "tmutil", "listlocalsnapshots", ".")
if err != nil {
Expand All @@ -164,17 +164,17 @@ func CreateShadowCopy(top string, shadowCopy bool, timeoutInSeconds int) (shadow
}
snapshotName := "com.apple.TimeMachine." + snapshotDate

r := regexp.MustCompile(`(?m)^(.+` + snapshotDate + `.*)$`)
snapshotNames := r.FindStringSubmatch(tmutilOutput)
if len(snapshotNames) > 0 {
snapshotName = snapshotNames[0]
snapshotNameRegex := regexp.MustCompile(`(?m)^(.+` + snapshotDate + `.*)$`)
matched = snapshotNameRegex.FindStringSubmatch(tmutilOutput)
if len(matched) > 0 {
snapshotName = matched[0]
} else {
LOG_WARN("VSS_CREATE", "Error while using 'tmutil listlocalsnapshots' to find snapshot name. Will fallback to 'com.apple.TimeMachine.SNAPSHOT_DATE'")
LOG_INFO("VSS_CREATE", "Can't find the snapshot name with 'tmutil listlocalsnapshots'; fallback to %s", snapshotName)
}

// Mount snapshot as readonly and hide from GUI i.e. Finder
_, err = CommandWithTimeout(timeoutInSeconds,
"/sbin/mount", "-t", "apfs", "-o", "nobrowse,-r,-s="+snapshotName, "/", snapshotPath)
"/sbin/mount", "-t", "apfs", "-o", "nobrowse,-r,-s="+snapshotName, "/System/Volumes/Data", snapshotPath)
if err != nil {
LOG_ERROR("VSS_CREATE", "Error while mounting snapshot: %v", err)
return top
Expand Down

2 comments on commit 7c36311

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/shadow-copy-vss-fails-on-macos-big-sur/4314/2

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/cli-2-7-2-is-now-available/4483/1

Please sign in to comment.