diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-08-20 18:18:36 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-08-20 18:18:36 +0200 |
commit | 9a1aa7fe443438fdfdab89d77aa07c51b633644c (patch) | |
tree | 1d90ea6007fc59c3012efb17d14370c890b2805e /repo.go | |
parent | 9f98d6ef4931f04b9023264f0e3408e4529c977d (diff) | |
download | dna-backup-9a1aa7fe443438fdfdab89d77aa07c51b633644c.tar.gz dna-backup-9a1aa7fe443438fdfdab89d77aa07c51b633644c.zip |
initial repo tree
Diffstat (limited to 'repo.go')
-rw-r--r-- | repo.go | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -1,13 +1,39 @@ +/* +Manage a deduplicated versionned backups repository. + +Sample repository: + +``` +repo/ +├── 00000/ +│ ├── chunks/ +│ │ ├── 000000000000000 +│ │ ├── 000000000000001 +│ │ ├── 000000000000002 +│ │ ├── 000000000000003 +│ ├── dentries +│ └── recipe +└── 00001/ + ├── chunks/ + │ ├── 000000000000000 + │ ├── 000000000000001 + ├── dentries + └── recipe +``` +*/ + package main import ( "fmt" "io" "io/fs" + "io/ioutil" "log" "os" "path" "path/filepath" + "strconv" ) const ( @@ -19,6 +45,44 @@ type File struct { Size int64 } +func Commit(source string, repo string) { + latest := GetLastVersion(repo) + new := latest + 1 + newPath := path.Join(repo, fmt.Sprintf("%05d", new)) + newChunkPath := path.Join(newPath, "chunks") + os.Mkdir(newPath, 0775) + os.Mkdir(newChunkPath, 0775) + files := make(chan File) + newChunks := make(chan []byte) + oldChunks := make(chan []byte) + go LoadChunks(repo, oldChunks) + go ListFiles(source, files) + go ReadFiles(files, newChunks) + StoreChunks(newChunkPath, newChunks) +} + +func GetLastVersion(repo string) int { + v := -1 + files, err := ioutil.ReadDir(repo) + if err != nil { + log.Fatalln(err) + } + for _, f := range files { + if !f.IsDir() { + continue + } + num, err := strconv.Atoi(f.Name()) + if err != nil { + log.Println(err) + continue + } + if num > v { + v = num + } + } + return v +} + func ListFiles(path string, files chan<- File) { err := filepath.Walk(path, func(p string, i fs.FileInfo, err error) error { |