72 lines
2.0 KiB
Go
Executable File
72 lines
2.0 KiB
Go
Executable File
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.inhome.blapointe.com/local/args"
|
|
"gitea.inhome.blapointe.com/local/lastn/lastn"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
conf := config()
|
|
log.Println(conf)
|
|
lastn, err := lastn.New(conf)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
actions := []func() error{}
|
|
switch conf.Cmd {
|
|
case "backup":
|
|
actions = append(actions, lastn.Push, lastn.Clean)
|
|
case "list":
|
|
actions = append(actions, lastn.List)
|
|
case "clean":
|
|
actions = append(actions, lastn.Clean)
|
|
case "restore":
|
|
actions = append(actions, lastn.Restore)
|
|
default:
|
|
panic(fmt.Sprintf("not impl: %s", conf.Cmd))
|
|
}
|
|
for _, action := range actions {
|
|
if err := action(); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func config() lastn.Config {
|
|
as := args.NewArgSet()
|
|
as.Append(args.STRING, "cmd", "[backup, restore, list, clean]", "backup")
|
|
as.Append(args.INT, "n", "number of backups to retain", 5)
|
|
as.Append(args.STRING, "root", "path to root", "./public")
|
|
as.Append(args.STRING, "store", "type of store, like [map rclone]", "map")
|
|
as.Append(args.STRING, "storeaddr", "addr of store", "")
|
|
as.Append(args.STRING, "storeuser", "user of store", "")
|
|
as.Append(args.STRING, "storepass", "pass of store", "")
|
|
as.Append(args.STRING, "ns", "ns for backups", path.Join("lastn", "dev"))
|
|
as.Append(args.STRING, "rclone-conf", "path to rclone conf", path.Join(os.Getenv("HOME"), "/.config/rclone/rclone.conf"))
|
|
as.Append(args.STRING, "rclone-alias", "rclone backend name", "blapointe-drive-enc")
|
|
if err := as.Parse(); err != nil {
|
|
panic(err)
|
|
}
|
|
root, err := filepath.Abs(as.Get("root").GetString())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return lastn.Config{
|
|
N: as.Get("n").GetInt(),
|
|
RcloneConf: as.Get("rclone-conf").GetString(),
|
|
RcloneAlias: as.Get("rclone-alias").GetString(),
|
|
Root: root,
|
|
Ns: as.Get("ns").GetString(),
|
|
Store: as.Get("store").GetString(),
|
|
StoreAddr: as.Get("storeaddr").GetString(),
|
|
StoreUser: as.Get("storeuser").GetString(),
|
|
StorePass: as.Get("storepass").GetString(),
|
|
Cmd: as.Get("cmd").GetString(),
|
|
}
|
|
}
|