backuper/main.go

96 lines
1.7 KiB
Go
Raw Permalink Normal View History

2023-03-11 14:13:35 +05:00
package main
import (
"log"
"os"
"path/filepath"
)
func init() {
log.SetFlags(0)
}
func main() {
if len(os.Args) < 2 {
2023-03-11 14:13:35 +05:00
printUsage()
os.Exit(1)
}
switch os.Args[1] {
case "f":
2023-03-11 14:13:35 +05:00
config, err := LoadConfig(os.Args[2])
if err != nil {
log.Fatalln(err)
2023-03-11 14:13:35 +05:00
}
err = config.FullBackup()
2023-03-11 14:13:35 +05:00
if err != nil {
log.Fatalln(err)
2023-03-11 14:13:35 +05:00
}
case "i":
2023-03-11 14:13:35 +05:00
config, err := LoadConfig(os.Args[2])
if err != nil {
log.Fatalln(err)
}
err = config.IncrementalBackup()
2023-03-11 14:13:35 +05:00
if err != nil {
log.Fatalln(err)
2023-03-11 14:13:35 +05:00
}
case "s":
config, err := LoadConfig(os.Args[2])
if err != nil {
log.Fatalln("read config error:", err)
2023-03-11 14:13:35 +05:00
}
idx, err := config.FindAll(os.Args[3])
if err != nil {
config.fatalln("search error:", err)
2023-03-11 14:13:35 +05:00
}
idx.ViewFileVersions(os.Stdout)
2023-03-11 14:13:35 +05:00
case "r":
config, err := LoadConfig(os.Args[2])
if err != nil {
log.Fatalln(err)
}
2023-04-08 14:02:36 +05:00
t, err := parseTime(os.Args[4])
if err != nil {
config.fatalln(err)
2023-03-11 14:13:35 +05:00
}
plan, err := config.extractionPlan(os.Args[3], t)
2023-03-11 14:13:35 +05:00
if err != nil {
log.Fatalln(err)
}
err = config.extract(plan, os.Args[5])
2023-03-11 14:13:35 +05:00
if err != nil {
log.Fatalln(err)
}
case "t":
config, err := LoadConfig(os.Args[2])
if err != nil {
log.Fatalln(err)
}
_, err = config.index(true)
2023-03-11 14:13:35 +05:00
if err != nil {
log.Fatalln(err)
2023-03-11 14:13:35 +05:00
}
default:
printUsage()
}
}
func printUsage() {
bin := filepath.Base(os.Args[0])
log.Print("Usage:\n")
log.Printf("%s i <config file path> - do incremental backup\n", bin)
log.Printf("%s f <config file path> - do full backup\n", bin)
log.Printf("%s s <config file path> <mask> - search file(s) in backup\n", bin)
log.Printf("%s r <config file path> <mask> <dd.mm.yyyy hh:mm> <path> - recover file(s) from backup\n", bin)
log.Printf("%s t <config file path> - test archive for errors\n", bin)
2023-03-11 14:13:35 +05:00
}