mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-16 00:03:34 +00:00
Merge pull request #180 from niknah/dry_run
Added backup --dry-run option.
This commit is contained in:
1
GUIDE.md
1
GUIDE.md
@@ -50,6 +50,7 @@ OPTIONS:
|
||||
-stats show statistics during and after backup
|
||||
-threads <n> number of uploading threads
|
||||
-limit-rate <kB/s> the maximum upload rate (in kilobytes/sec)
|
||||
-dry-run dry run for testing, don't backup anything. Use with -stats and -d
|
||||
-vss enable the Volume Shadow Copy service (Windows only)
|
||||
-storage <storage name> backup to the specified storage instead of the default one
|
||||
```
|
||||
|
||||
@@ -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")
|
||||
@@ -1211,6 +1213,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() {}
|
||||
@@ -1109,8 +1115,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
|
||||
}
|
||||
|
||||
|
||||
@@ -134,13 +134,17 @@ 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)
|
||||
} else {
|
||||
LOG_DEBUG("CHUNK_UPLOAD", "Uploading was skipped for chunk %s", chunkID)
|
||||
}
|
||||
|
||||
uploader.completionFunc(chunk, task.chunkIndex, false, chunkSize, chunk.GetLength())
|
||||
atomic.AddInt32(&uploader.numberOfUploadingTasks, -1)
|
||||
return true
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -594,6 +594,7 @@ func (manager *SnapshotManager) ListAllFiles(storage Storage, top string) (allFi
|
||||
}
|
||||
}
|
||||
|
||||
if !manager.config.dryRun {
|
||||
if top == "chunks/" {
|
||||
// We're listing all chunks so this is the perfect place to detect if a directory contains too many
|
||||
// chunks. Create sub-directories if necessary
|
||||
@@ -610,6 +611,7 @@ func (manager *SnapshotManager) ListAllFiles(storage Storage, top string) (allFi
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allFiles, allSizes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user