package main import ( "context" "log/slog" "os" "github.com/bugsnag/bugsnag-go/v2" "github.com/joho/godotenv" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" ) func main() { ctx := context.Background() err := godotenv.Load(".env") if err != nil { if !os.IsNotExist(err) { slog.Error("load env", "error", err) return } } configureBugsnag() minioClient, err := createMinioClient() if err != nil { slog.Error("create minio client", "error", err) bugsnag.Notify(err) return } bucketName := os.Getenv("S3_BUCKET_NAME") err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{}) if err != nil { slog.Error("create bucket", "error", err) bugsnag.Notify(err) return } backupPDS(ctx, minioClient, bucketName) backupTangledKnot(ctx, minioClient, bucketName) } func createMinioClient() (*minio.Client, error) { endpoint := os.Getenv("S3_ENDPOINT") accessKeyID := os.Getenv("S3_ACCESS_ID") secretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY") useSSL := true return minio.New(endpoint, &minio.Options{ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""), Secure: useSSL, }) } func configureBugsnag() { apiKey := os.Getenv("BUGSNAG_API_KEY") if apiKey == "" { slog.Info("bugsnag not configured") return } bugsnag.Configure(bugsnag.Configuration{ APIKey: apiKey, ReleaseStage: "production", }) }