리팩토링
This commit is contained in:
68
cmd/main.go
Normal file
68
cmd/main.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.lhk.o-r.kr/freerer2/simple_backup/internal/backup"
|
||||
"git.lhk.o-r.kr/freerer2/simple_backup/internal/path"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("사용법: backup <원본경로> <백업경로> [옵션]")
|
||||
os.Exit(1)
|
||||
}
|
||||
src := os.Args[1]
|
||||
dst := os.Args[2]
|
||||
|
||||
fs := flag.NewFlagSet("backup", flag.ExitOnError)
|
||||
groupBy := fs.String("group-by", "", "백업 폴더 구조 기준: year, mon, day, hour, min, sec")
|
||||
snapshot := fs.String("snapshot", "", "스냅샷 기준: y, ym, ymd")
|
||||
dryRun := fs.Bool("dry-run", false, "복사하지 않고 어떤 파일이 복사되는지 출력")
|
||||
verbose := fs.Bool("verbose", false, "복사 로그 자세히 출력")
|
||||
force := fs.Bool("force", false, "속성 무시하고 무조건 덮어쓰기")
|
||||
_ = fs.Parse(os.Args[3:])
|
||||
|
||||
now := time.Now()
|
||||
backupPath := dst
|
||||
|
||||
if *groupBy != "" {
|
||||
backupPath = path.GetGroupByFolder(dst, *groupBy, now)
|
||||
}
|
||||
|
||||
if *snapshot != "" {
|
||||
var snapshotFolder string
|
||||
switch *snapshot {
|
||||
case "y":
|
||||
snapshotFolder = fmt.Sprintf("%d", now.Year())
|
||||
case "ym":
|
||||
snapshotFolder = fmt.Sprintf("%d%02d", now.Year(), int(now.Month()))
|
||||
case "ymd":
|
||||
snapshotFolder = fmt.Sprintf("%d%02d%02d", now.Year(), int(now.Month()), now.Day())
|
||||
default:
|
||||
fmt.Printf("오류: 지원하지 않는 snapshot 옵션입니다: %s\n", *snapshot)
|
||||
os.Exit(1)
|
||||
}
|
||||
backupPath = fmt.Sprintf("%s/snapshots/%s", dst, snapshotFolder)
|
||||
}
|
||||
|
||||
fmt.Println("원본 경로:", src)
|
||||
fmt.Println("최종 백업 경로:", backupPath)
|
||||
if *dryRun {
|
||||
fmt.Println("Dry-run 모드 활성화됨")
|
||||
}
|
||||
if *verbose {
|
||||
fmt.Println("Verbose 모드 활성화됨")
|
||||
}
|
||||
if *force {
|
||||
fmt.Println("Force 모드 활성화됨")
|
||||
}
|
||||
|
||||
if err := backup.RunBackup(src, backupPath, *dryRun, *verbose, *force); err != nil {
|
||||
fmt.Println("백업 중 오류 발생:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user