backblaze-backup/cmd/cleanup.go

33 lines
770 B
Go

package cmd
import (
"context"
"log"
"os"
"gitea.urkob.com/urko/backblaze-backup/internal/services"
"gitea.urkob.com/urko/backblaze-backup/kit/config"
"github.com/spf13/cobra"
)
var Cleanup = &cobra.Command{
Use: "cleanup",
Short: "Handle clenaup for multiple versions of file in Backblaze",
Run: func(cmd *cobra.Command, args []string) {
log.SetFlags(log.Ldate | log.Lmicroseconds)
ctx, cancel := context.WithCancel(signalContext(cmd.Context()))
defer cancel()
envFile := ""
if os.Getenv("BACKBLAZE_ENV") == "dev" {
envFile = ".env"
}
cfg := config.NewConfig(envFile)
bbService := services.NewBackBlaze(cfg.BbId, cfg.BbKey)
if err := bbService.CleanUp(ctx, cancel); err != nil {
log.Fatalln("bbService.CleanUp()", err)
}
},
}