자잘한 내용 수
This commit is contained in:
32
README.md
32
README.md
@@ -1,5 +1,35 @@
|
||||
# simple_backup
|
||||
## build
|
||||
## Build
|
||||
```sh
|
||||
$ go build -o backup git.lhk.o-r.kr/freerer2/simple_backup/cmd
|
||||
```
|
||||
|
||||
## Usage
|
||||
```sh
|
||||
사용법: backup <원본경로> <백업경로> [옵션]
|
||||
|
||||
옵션:
|
||||
-g, --group-by 백업 폴더 구조 기준 (기본값: day)
|
||||
가능한 값: year, mon, day, hour, min, sec
|
||||
|
||||
-i, --incremental 증분 백업 사용
|
||||
기존 백업과 비교하여 변경된 파일만 백업
|
||||
|
||||
-c, --compare 파일 비교 방식 선택 (기본값: time)
|
||||
- time: 파일 수정 시간으로 비교
|
||||
- hash: 파일 내용의 해시값으로 비교
|
||||
|
||||
-d, --dry-run 실행하지 않고 어떤 파일이 복사되는지 출력
|
||||
실제 파일 시스템을 변경하지 않음
|
||||
|
||||
-v, --verbose 복사 로그 자세히 출력
|
||||
진행 상황과 세부 정보를 표시
|
||||
|
||||
-f, --force 속성 무시하고 무조건 덮어쓰기
|
||||
기존 파일 존재 시 강제로 덮어씀
|
||||
|
||||
예시:
|
||||
backup /source /simple_backup --group-by day --compare hash
|
||||
backup /home/user/docs /simple_backup/docs -i -v
|
||||
backup /data /simple_backup -d --force
|
||||
```
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -45,12 +46,13 @@ func showHelp() {
|
||||
|
||||
-i, --incremental 증분 백업 사용
|
||||
기존 백업과 비교하여 변경된 파일만 백업
|
||||
(.backup_meta.json을 생성하여 이용함.)
|
||||
|
||||
-c, --compare 파일 비교 방식 선택 (기본값: time)
|
||||
- time: 파일 수정 시간으로 비교
|
||||
- hash: 파일 내용의 해시값으로 비교
|
||||
|
||||
-d, --dry-run 하지 않고 어떤 파일이 복사되는지 출력
|
||||
-d, --dry-run 실하지 않고 어떤 파일이 복사되는지 출력
|
||||
실제 파일 시스템을 변경하지 않음
|
||||
|
||||
-v, --verbose 복사 로그 자세히 출력
|
||||
@@ -64,7 +66,7 @@ func showHelp() {
|
||||
backup /home/user/docs /simple_backup/docs -i -v
|
||||
backup /data /simple_backup -d --force
|
||||
|
||||
자세한 정보: https://github.com/yourusername/backup`
|
||||
자세한 정보: https://git.lhk.o-r.kr/simple-utils/simple_backup`
|
||||
|
||||
fmt.Println(helpText)
|
||||
}
|
||||
@@ -246,7 +248,7 @@ func main() {
|
||||
}
|
||||
|
||||
if err := backup.RunBackup(ctx, opts.Src, backupPath, backupOpts); err != nil {
|
||||
if err == context.Canceled {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
fmt.Println("\n백업이 취소되었습니다")
|
||||
} else {
|
||||
fmt.Println("\n백업 중 오류 발생:", err)
|
||||
|
||||
@@ -106,7 +106,7 @@ func calculateFileHash(path string) (string, error) {
|
||||
}
|
||||
|
||||
func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
|
||||
var backupF = false
|
||||
if opts.dirCache == nil {
|
||||
opts.dirCache = path.NewDirCache()
|
||||
}
|
||||
@@ -271,6 +271,7 @@ func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
|
||||
progress.Status = "복사됨"
|
||||
if opts.Progress != nil {
|
||||
backupF = true
|
||||
opts.Progress(progress)
|
||||
}
|
||||
}
|
||||
@@ -283,19 +284,27 @@ func RunBackup(ctx context.Context, src, dst string, opts Options) error {
|
||||
}
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dst)
|
||||
if err != nil {
|
||||
return fmt.Errorf("디렉토리 읽기 실패: %w", err)
|
||||
}
|
||||
|
||||
if len(entries) == 0 {
|
||||
err := os.Remove(dst)
|
||||
if !opts.DryRun {
|
||||
entries, err := os.ReadDir(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("디렉토리 읽기 실패: %w", err)
|
||||
}
|
||||
|
||||
if len(entries) == 0 {
|
||||
err := os.Remove(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts.Logger.Printf("백업된 내역이 없습니다.\n")
|
||||
} else {
|
||||
fmt.Println("백업이 성공적으로 완료되었습니다.")
|
||||
}
|
||||
opts.Logger.Printf("백업된 내역이 없습니다.")
|
||||
} else {
|
||||
fmt.Println("\n백업이 성공적으로 완료되었습니다")
|
||||
if backupF {
|
||||
fmt.Println("백업이 성공적으로 완료되었습니다.")
|
||||
} else {
|
||||
opts.Logger.Printf("백업된 내역이 없습니다.\n")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user