1. 증분 백업 버그 수정
2. 일반 백업 해쉬 비교 추가
This commit is contained in:
@@ -199,7 +199,7 @@ func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
dstInfo, err := os.Stat(dstPath)
|
||||
fileExists := err == nil
|
||||
|
||||
if fileExists && !opts.Force {
|
||||
if !opts.Force {
|
||||
if opts.Incremental {
|
||||
// 증분 백업 모드에서는 메타데이터를 확인
|
||||
srcInfo, err := os.Stat(srcPath)
|
||||
@@ -230,30 +230,32 @@ func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
|
||||
meta.Files[relPath] = newValue
|
||||
} else {
|
||||
// 일반 모드에서는 크기와 수정 시간만 비교
|
||||
srcInfo, err := os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("원본 파일 정보를 읽을 수 없습니다: %w", err)
|
||||
}
|
||||
if fileExists {
|
||||
// 일반 모드에서는 크기와 수정 시간만 비교
|
||||
srcInfo, err := os.Stat(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("원본 파일 정보를 읽을 수 없습니다: %w", err)
|
||||
}
|
||||
|
||||
switch opts.CompareMode {
|
||||
case CompareTime:
|
||||
if srcInfo.Size() == dstInfo.Size() && srcInfo.ModTime().Equal(dstInfo.ModTime()) {
|
||||
opts.Logger.Printf("건너뜀 (시간 동일): %s\n", relPath)
|
||||
continue
|
||||
}
|
||||
case CompareHash:
|
||||
srcHash, err := calculateFileHash(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("원본 파일 해시를 계산할 수 없습니다: %w", err)
|
||||
}
|
||||
dstHash, err := calculateFileHash(dstPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("대상 파일 해시를 계산할 수 없습니다: %w", err)
|
||||
}
|
||||
if srcHash == dstHash {
|
||||
opts.Logger.Printf("건너뜀 (해시 동일): %s\n", relPath)
|
||||
continue
|
||||
switch opts.CompareMode {
|
||||
case CompareTime:
|
||||
if srcInfo.Size() == dstInfo.Size() && srcInfo.ModTime().Equal(dstInfo.ModTime()) {
|
||||
opts.Logger.Printf("건너뜀 (시간 동일): %s\n", relPath)
|
||||
continue
|
||||
}
|
||||
case CompareHash:
|
||||
srcHash, err := calculateFileHash(srcPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("원본 파일 해시를 계산할 수 없습니다: %w", err)
|
||||
}
|
||||
dstHash, err := calculateFileHash(dstPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("대상 파일 해시를 계산할 수 없습니다: %w", err)
|
||||
}
|
||||
if srcHash == dstHash {
|
||||
opts.Logger.Printf("건너뜀 (해시 동일): %s\n", relPath)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,7 +265,6 @@ func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
if err := copyFile(srcPath, dstPath); err != nil {
|
||||
return fmt.Errorf("파일을 복사할 수 없습니다: %w", err)
|
||||
}
|
||||
|
||||
opts.Logger.Printf("복사됨: %s\n", relPath)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user