2023-07-18 15:00:12 +02:00
|
|
|
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) {
|
2023-07-26 17:59:14 +02:00
|
|
|
log.SetFlags(log.Ldate | log.Lmicroseconds)
|
2023-07-18 15:00:12 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|