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()
|
|
|
|
|
2023-08-12 09:52:04 +02:00
|
|
|
bucketName, err := cmd.Flags().GetString("bucket")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("bucket %w", err)
|
|
|
|
}
|
|
|
|
|
2023-07-18 15:00:12 +02:00
|
|
|
envFile := ""
|
|
|
|
if os.Getenv("BACKBLAZE_ENV") == "dev" {
|
|
|
|
envFile = ".env"
|
|
|
|
}
|
|
|
|
cfg := config.NewConfig(envFile)
|
|
|
|
|
|
|
|
bbService := services.NewBackBlaze(cfg.BbId, cfg.BbKey)
|
2023-08-12 09:52:04 +02:00
|
|
|
if err := bbService.CleanUp(ctx, cancel, bucketName); err != nil {
|
2023-07-18 15:00:12 +02:00
|
|
|
log.Fatalln("bbService.CleanUp()", err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|