mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-02 03:34:39 -06:00
Change snapshot source path from / to /System/Volumes/Data
Also use a regex to extract the snapshot date from tmutil output.
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -77,19 +76,19 @@ func DeleteShadowCopy() {
|
|||||||
|
|
||||||
err := exec.Command("/sbin/umount", "-f", snapshotPath).Run()
|
err := exec.Command("/sbin/umount", "-f", snapshotPath).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("VSS_DELETE", "Error while unmounting snapshot")
|
LOG_WARN("VSS_DELETE", "Error while unmounting snapshot: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = exec.Command("tmutil", "deletelocalsnapshots", snapshotDate).Run()
|
err = exec.Command("tmutil", "deletelocalsnapshots", snapshotDate).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LOG_ERROR("VSS_DELETE", "Error while deleting local snapshot")
|
LOG_WARN("VSS_DELETE", "Error while deleting local snapshot: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.RemoveAll(snapshotPath)
|
err = os.RemoveAll(snapshotPath)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,12 +149,13 @@ func CreateShadowCopy(top string, shadowCopy bool, timeoutInSeconds int) (shadow
|
|||||||
return top
|
return top
|
||||||
}
|
}
|
||||||
|
|
||||||
colonPos := strings.IndexByte(tmutilOutput, ':')
|
snapshotDateRegex := regexp.MustCompile(`:\s+([0-9\-]+)`)
|
||||||
if colonPos < 0 {
|
matched := snapshotDateRegex.FindStringSubmatch(tmutilOutput)
|
||||||
|
if matched == nil {
|
||||||
LOG_ERROR("VSS_CREATE", "Snapshot creation failed: %s", tmutilOutput)
|
LOG_ERROR("VSS_CREATE", "Snapshot creation failed: %s", tmutilOutput)
|
||||||
return top
|
return top
|
||||||
}
|
}
|
||||||
snapshotDate = strings.TrimSpace(tmutilOutput[colonPos+1:])
|
snapshotDate = matched[1]
|
||||||
|
|
||||||
tmutilOutput, err = CommandWithTimeout(timeoutInSeconds, "tmutil", "listlocalsnapshots", ".")
|
tmutilOutput, err = CommandWithTimeout(timeoutInSeconds, "tmutil", "listlocalsnapshots", ".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -164,17 +164,17 @@ func CreateShadowCopy(top string, shadowCopy bool, timeoutInSeconds int) (shadow
|
|||||||
}
|
}
|
||||||
snapshotName := "com.apple.TimeMachine." + snapshotDate
|
snapshotName := "com.apple.TimeMachine." + snapshotDate
|
||||||
|
|
||||||
r := regexp.MustCompile(`(?m)^(.+` + snapshotDate + `.*)$`)
|
snapshotNameRegex := regexp.MustCompile(`(?m)^(.+` + snapshotDate + `.*)$`)
|
||||||
snapshotNames := r.FindStringSubmatch(tmutilOutput)
|
matched = snapshotNameRegex.FindStringSubmatch(tmutilOutput)
|
||||||
if len(snapshotNames) > 0 {
|
if len(matched) > 0 {
|
||||||
snapshotName = snapshotNames[0]
|
snapshotName = matched[0]
|
||||||
} else {
|
} 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
|
// Mount snapshot as readonly and hide from GUI i.e. Finder
|
||||||
_, err = CommandWithTimeout(timeoutInSeconds,
|
_, 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 {
|
if err != nil {
|
||||||
LOG_ERROR("VSS_CREATE", "Error while mounting snapshot: %v", err)
|
LOG_ERROR("VSS_CREATE", "Error while mounting snapshot: %v", err)
|
||||||
return top
|
return top
|
||||||
|
|||||||
Reference in New Issue
Block a user