backblaze-backup/cmd/main.go

52 lines
1.3 KiB
Go
Raw Normal View History

2023-07-10 12:19:21 +02:00
package main
import (
"fmt"
"log"
"os"
"gitea.urkob.com/urko/backblaze-backup/internal/services"
"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)
}
id := os.Getenv("BB_ID")
key := os.Getenv("BB_KEY")
bbService := services.NewBackBlaze(id, key).WithBucket(bucketName).WithDir(dir).WithFile(filePath)
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)
}
}