backblaze-backup/cmd/cleanup.go

38 lines
891 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()
bucketName, err := cmd.Flags().GetString("bucket")
if err != nil {
log.Fatalln("bucket %w", err)
}
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, bucketName); err != nil {
log.Fatalln("bbService.CleanUp()", err)
}
},
}