mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-17 16:53:19 +00:00
Added backup --dry-run option.
This commit is contained in:
@@ -623,12 +623,14 @@ func backupRepository(context *cli.Context) {
|
||||
|
||||
enableVSS := context.Bool("vss")
|
||||
|
||||
dryRun := context.Bool("dry-run")
|
||||
uploadRateLimit := context.Int("limit-rate")
|
||||
storage.SetRateLimits(0, uploadRateLimit)
|
||||
backupManager := duplicacy.CreateBackupManager(preference.SnapshotID, storage, repository, password)
|
||||
duplicacy.SavePassword(*preference, "password", password)
|
||||
|
||||
backupManager.SetupSnapshotCache(preference.Name)
|
||||
backupManager.SetDryRun(dryRun)
|
||||
backupManager.Backup(repository, quickMode, threads, context.String("t"), showStatistics, enableVSS)
|
||||
|
||||
runScript(context, preference.Name, "post")
|
||||
@@ -1202,6 +1204,10 @@ func main() {
|
||||
Usage: "the maximum upload rate (in kilobytes/sec)",
|
||||
Argument: "<kB/s>",
|
||||
},
|
||||
cli.BoolFlag {
|
||||
Name: "dry-run",
|
||||
Usage: "Dry run for testing, don't backup anything. Use with -stats and -d",
|
||||
},
|
||||
cli.BoolFlag {
|
||||
Name: "vss",
|
||||
Usage: "enable the Volume Shadow Copy service (Windows only)",
|
||||
|
||||
@@ -36,6 +36,10 @@ type BackupManager struct {
|
||||
}
|
||||
|
||||
|
||||
func (manager *BackupManager) SetDryRun(dryRun bool) {
|
||||
manager.config.dryRun = dryRun
|
||||
}
|
||||
|
||||
|
||||
// CreateBackupManager creates a backup manager using the specified 'storage'. 'snapshotID' is a unique id to
|
||||
// identify snapshots created for this repository. 'top' is the top directory of the repository. 'password' is the
|
||||
@@ -630,7 +634,9 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta
|
||||
}
|
||||
skippedFiles = append(skippedFiles, fileReader.SkippedFiles...)
|
||||
|
||||
if !manager.config.dryRun {
|
||||
manager.SnapshotManager.CleanSnapshotCache(localSnapshot, nil)
|
||||
}
|
||||
LOG_INFO("BACKUP_END", "Backup for %s at revision %d completed", top, localSnapshot.Revision)
|
||||
|
||||
RunAtError = func() {}
|
||||
@@ -1108,8 +1114,9 @@ func (manager *BackupManager) UploadSnapshot(chunkMaker *ChunkMaker, uploader *C
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("snapshots/%s/%d", manager.snapshotID, snapshot.Revision)
|
||||
if !manager.config.dryRun {
|
||||
manager.SnapshotManager.UploadFile(path, path, description)
|
||||
|
||||
}
|
||||
return totalSnapshotChunkSize, numberOfNewSnapshotChunks, totalUploadedSnapshotChunkSize, totalUploadedSnapshotChunkBytes
|
||||
}
|
||||
|
||||
@@ -1598,7 +1605,9 @@ func (manager *BackupManager) CopySnapshots(otherManager *BackupManager, snapsho
|
||||
chunkUploader.Stop()
|
||||
|
||||
for _, snapshot := range snapshots {
|
||||
if !manager.config.dryRun {
|
||||
otherManager.storage.CreateDirectory(0, fmt.Sprintf("snapshots/%s", manager.snapshotID))
|
||||
}
|
||||
description, _ := snapshot.MarshalJSON()
|
||||
path := fmt.Sprintf("snapshots/%s/%d", manager.snapshotID, snapshot.Revision)
|
||||
otherManager.SnapshotManager.UploadFile(path, path, description)
|
||||
|
||||
@@ -134,11 +134,13 @@ func (uploader *ChunkUploader) Upload(threadIndex int, task ChunkUploadTask) boo
|
||||
return false
|
||||
}
|
||||
|
||||
if !uploader.config.dryRun {
|
||||
err = uploader.storage.UploadFile(threadIndex, chunkPath, chunk.GetBytes())
|
||||
if err != nil {
|
||||
LOG_ERROR("UPLOAD_CHUNK", "Failed to upload the chunk %s: %v", chunkID, err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG("CHUNK_UPLOAD", "Chunk %s has been uploaded", chunkID)
|
||||
uploader.completionFunc(chunk, task.chunkIndex, false, chunkSize, chunk.GetLength())
|
||||
|
||||
@@ -55,6 +55,7 @@ type Config struct {
|
||||
|
||||
chunkPool chan *Chunk `json:"-"`
|
||||
numberOfChunks int32
|
||||
dryRun bool
|
||||
}
|
||||
|
||||
// Create an alias to avoid recursive calls on Config.MarshalJSON
|
||||
|
||||
@@ -2215,10 +2215,12 @@ func (manager *SnapshotManager) DownloadFile(path string, derivationKey string)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !manager.config.dryRun {
|
||||
err = manager.snapshotCache.UploadFile(0, path, manager.fileChunk.GetBytes())
|
||||
if err != nil {
|
||||
LOG_WARN("DOWNLOAD_FILE_CACHE", "Failed to add the file %s to the snapshot cache: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG("DOWNLOAD_FILE", "Downloaded file %s", path)
|
||||
|
||||
@@ -2227,6 +2229,9 @@ func (manager *SnapshotManager) DownloadFile(path string, derivationKey string)
|
||||
|
||||
// UploadFile uploads a non-chunk file from the storage.
|
||||
func (manager *SnapshotManager) UploadFile(path string, derivationKey string, content []byte) bool {
|
||||
if manager.config.dryRun {
|
||||
return true
|
||||
}
|
||||
manager.fileChunk.Reset(false)
|
||||
manager.fileChunk.Write(content)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user