mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-06 00:03:38 +00:00
allow skip setting uid/gid on restored files
This commit is contained in:
@@ -691,6 +691,8 @@ func restoreRepository(context *cli.Context) {
|
|||||||
quickMode := !context.Bool("hash")
|
quickMode := !context.Bool("hash")
|
||||||
overwrite := context.Bool("overwrite")
|
overwrite := context.Bool("overwrite")
|
||||||
deleteMode := context.Bool("delete")
|
deleteMode := context.Bool("delete")
|
||||||
|
setOwner := !context.Bool("ignore-owner")
|
||||||
|
|
||||||
showStatistics := context.Bool("stats")
|
showStatistics := context.Bool("stats")
|
||||||
|
|
||||||
var patterns []string
|
var patterns []string
|
||||||
@@ -732,7 +734,7 @@ func restoreRepository(context *cli.Context) {
|
|||||||
duplicacy.SavePassword(*preference, "password", password)
|
duplicacy.SavePassword(*preference, "password", password)
|
||||||
|
|
||||||
backupManager.SetupSnapshotCache(preference.Name)
|
backupManager.SetupSnapshotCache(preference.Name)
|
||||||
backupManager.Restore(repository, revision, true, quickMode, threads, overwrite, deleteMode, showStatistics, patterns)
|
backupManager.Restore(repository, revision, true, quickMode, threads, overwrite, deleteMode, setOwner, showStatistics, patterns)
|
||||||
|
|
||||||
runScript(context, preference.Name, "post")
|
runScript(context, preference.Name, "post")
|
||||||
}
|
}
|
||||||
@@ -1279,6 +1281,10 @@ func main() {
|
|||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "delete files not in the snapshot",
|
Usage: "delete files not in the snapshot",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "ignore-owner",
|
||||||
|
Usage: "do not set the original uid/gid on restored files",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "stats",
|
Name: "stats",
|
||||||
Usage: "show statistics during and after restore",
|
Usage: "show statistics during and after restore",
|
||||||
|
|||||||
@@ -711,7 +711,7 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
|||||||
// the same as 'top'. 'quickMode' will bypass files with unchanged sizes and timestamps. 'deleteMode' will
|
// the same as 'top'. 'quickMode' will bypass files with unchanged sizes and timestamps. 'deleteMode' will
|
||||||
// remove local files that don't exist in the snapshot. 'patterns' is used to include/exclude certain files.
|
// remove local files that don't exist in the snapshot. 'patterns' is used to include/exclude certain files.
|
||||||
func (manager *BackupManager) Restore(top string, revision int, inPlace bool, quickMode bool, threads int, overwrite bool,
|
func (manager *BackupManager) Restore(top string, revision int, inPlace bool, quickMode bool, threads int, overwrite bool,
|
||||||
deleteMode bool, showStatistics bool, patterns []string) bool {
|
deleteMode bool, setOwner bool, showStatistics bool, patterns []string) bool {
|
||||||
|
|
||||||
startTime := time.Now().Unix()
|
startTime := time.Now().Unix()
|
||||||
|
|
||||||
@@ -878,7 +878,8 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
if quickMode {
|
if quickMode {
|
||||||
if file.IsSameAsFileInfo(stat) {
|
if file.IsSameAsFileInfo(stat) {
|
||||||
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", file.Path)
|
LOG_TRACE("RESTORE_SKIP", "File %s unchanged (by size and timestamp)", file.Path)
|
||||||
file.RestoreMetadata(fullPath, &stat)
|
// shouldn't this be skipped?
|
||||||
|
// file.RestoreMetadata(fullPath, &stat)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -903,7 +904,7 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
}
|
}
|
||||||
newFile.Close()
|
newFile.Close()
|
||||||
|
|
||||||
file.RestoreMetadata(fullPath, nil)
|
file.RestoreMetadata(fullPath, nil, setOwner)
|
||||||
if !showStatistics {
|
if !showStatistics {
|
||||||
LOG_INFO("DOWNLOAD_DONE", "Downloaded %s (0)", file.Path)
|
LOG_INFO("DOWNLOAD_DONE", "Downloaded %s (0)", file.Path)
|
||||||
}
|
}
|
||||||
@@ -915,9 +916,9 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
totalFileSize, downloadedFileSize, startDownloadingTime) {
|
totalFileSize, downloadedFileSize, startDownloadingTime) {
|
||||||
downloadedFileSize += file.Size
|
downloadedFileSize += file.Size
|
||||||
downloadedFiles = append(downloadedFiles, file)
|
downloadedFiles = append(downloadedFiles, file)
|
||||||
|
file.RestoreMetadata(fullPath, nil, setOwner)
|
||||||
}
|
}
|
||||||
|
|
||||||
file.RestoreMetadata(fullPath, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if deleteMode && len(patterns) == 0 {
|
if deleteMode && len(patterns) == 0 {
|
||||||
@@ -933,7 +934,7 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
|
|||||||
for _, entry := range remoteSnapshot.Files {
|
for _, entry := range remoteSnapshot.Files {
|
||||||
if entry.IsDir() && !entry.IsLink() {
|
if entry.IsDir() && !entry.IsLink() {
|
||||||
dir := joinPath(top, entry.Path)
|
dir := joinPath(top, entry.Path)
|
||||||
entry.RestoreMetadata(dir, nil)
|
entry.RestoreMetadata(dir, nil, setOwner)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ func (entry *Entry) String(maxSizeDigits int) string {
|
|||||||
return fmt.Sprintf("%*d %s %64s %s", maxSizeDigits, entry.Size, modifiedTime, entry.Hash, entry.Path)
|
return fmt.Sprintf("%*d %s %64s %s", maxSizeDigits, entry.Size, modifiedTime, entry.Hash, entry.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (entry *Entry) RestoreMetadata(fullPath string, fileInfo *os.FileInfo) bool {
|
func (entry *Entry) RestoreMetadata(fullPath string, fileInfo *os.FileInfo, setOwner bool) bool {
|
||||||
|
|
||||||
if fileInfo == nil {
|
if fileInfo == nil {
|
||||||
stat, err := os.Stat(fullPath)
|
stat, err := os.Stat(fullPath)
|
||||||
@@ -318,7 +318,11 @@ func (entry *Entry) RestoreMetadata(fullPath string, fileInfo *os.FileInfo) bool
|
|||||||
entry.SetAttributesToFile(fullPath)
|
entry.SetAttributesToFile(fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if setOwner {
|
||||||
return SetOwner(fullPath, entry, fileInfo)
|
return SetOwner(fullPath, entry, fileInfo)
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return -1 if 'left' should appear before 'right', 1 if opposite, and 0 if they are the same.
|
// Return -1 if 'left' should appear before 'right', 1 if opposite, and 0 if they are the same.
|
||||||
|
|||||||
Reference in New Issue
Block a user