feat: tune up backblaze script

This commit is contained in:
Urko 2023-07-10 12:19:21 +02:00
parent b89196ac0e
commit 11d9310f2d
3 changed files with 79 additions and 0 deletions

51
cmd/main.go Normal file
View File

@ -0,0 +1,51 @@
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)
}
}

14
go.mod Normal file
View File

@ -0,0 +1,14 @@
module gitea.urkob.com/urko/backblaze-backup
go 1.20
require (
github.com/kurin/blazer v0.5.3
github.com/spf13/cobra v1.7.0
golang.org/x/sync v0.3.0
)
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)

14
go.sum Normal file
View File

@ -0,0 +1,14 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kurin/blazer v0.5.3 h1:SAgYv0TKU0kN/ETfO5ExjNAPyMt2FocO2s/UlCHfjAk=
github.com/kurin/blazer v0.5.3/go.mod h1:4FCXMUWo9DllR2Do4TtBd377ezyAJ51vB5uTBjt0pGU=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=