2023-07-10 12:19:21 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"gitea.urkob.com/urko/backblaze-backup/internal/services"
|
2023-07-10 14:45:52 +02:00
|
|
|
"gitea.urkob.com/urko/backblaze-backup/kit/config"
|
2023-07-10 12:19:21 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "backblaze-backup",
|
|
|
|
Short: "Backblaze backup tool",
|
|
|
|
Long: `A tool to backup files and directories to Backblaze.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
filePath, err := cmd.Flags().GetString("file")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("file %w", err)
|
|
|
|
}
|
|
|
|
dir, err := cmd.Flags().GetString("dir")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("dir %w", err)
|
|
|
|
}
|
|
|
|
bucketName, err := cmd.Flags().GetString("bucket")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("bucket %w", err)
|
|
|
|
}
|
|
|
|
|
2023-07-10 14:45:52 +02:00
|
|
|
envFile := ""
|
|
|
|
if os.Getenv("BACKBLAZE_ENV") == "dev" {
|
|
|
|
envFile = ".env"
|
|
|
|
}
|
|
|
|
cfg := config.NewConfig(envFile)
|
2023-07-10 12:19:21 +02:00
|
|
|
|
2023-07-10 14:45:52 +02:00
|
|
|
bbService := services.NewBackBlaze(cfg.BbId, cfg.BbKey).WithBucket(bucketName).WithDir(dir).WithFile(filePath)
|
2023-07-10 12:19:21 +02:00
|
|
|
if err := bbService.Sync(); err != nil {
|
|
|
|
log.Fatalln("bbService.Sync()", err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.PersistentFlags().String("file", "", "absolute path of the file you want to upload to backblaze")
|
|
|
|
rootCmd.PersistentFlags().String("dir", "", "absolute path of the directory you want to upload to backblaze")
|
|
|
|
rootCmd.PersistentFlags().String("bucket", "", "backblaze bucket name")
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|