mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-04 20:54:44 -06:00
Merge pull request #180 from niknah/dry_run
Added backup --dry-run option.
This commit is contained in:
@@ -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...)
|
||||
|
||||
manager.SnapshotManager.CleanSnapshotCache(localSnapshot, nil)
|
||||
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)
|
||||
manager.SnapshotManager.UploadFile(path, path, description)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
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)
|
||||
}
|
||||
|
||||
LOG_DEBUG("CHUNK_UPLOAD", "Chunk %s has been uploaded", 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,19 +594,21 @@ func (manager *SnapshotManager) ListAllFiles(storage Storage, top string) (allFi
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if len(files) > 1024 && !storage.IsFastListing() {
|
||||
for i := 0; i < 256; i++ {
|
||||
subdir := dir + fmt.Sprintf("%02x\n", i)
|
||||
manager.storage.CreateDirectory(0, subdir)
|
||||
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
|
||||
if len(files) > 1024 && !storage.IsFastListing() {
|
||||
for i := 0; i < 256; i++ {
|
||||
subdir := dir + fmt.Sprintf("%02x\n", i)
|
||||
manager.storage.CreateDirectory(0, subdir)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Remove chunk sub-directories that are empty
|
||||
if len(files) == 0 && strings.HasPrefix(dir, "chunks/") && dir != "chunks/" {
|
||||
storage.DeleteFile(0, dir)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Remove chunk sub-directories that are empty
|
||||
if len(files) == 0 && strings.HasPrefix(dir, "chunks/") && dir != "chunks/" {
|
||||
storage.DeleteFile(0, dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user