A tool for backing up ATProto related data to S3
1package main
2
3import (
4 "context"
5 "log/slog"
6 "os"
7
8 "github.com/bugsnag/bugsnag-go/v2"
9 "github.com/joho/godotenv"
10 "github.com/minio/minio-go/v7"
11 "github.com/minio/minio-go/v7/pkg/credentials"
12)
13
14func main() {
15 ctx := context.Background()
16
17 err := godotenv.Load(".env")
18 if err != nil {
19 if !os.IsNotExist(err) {
20 slog.Error("load env", "error", err)
21 return
22 }
23 }
24
25 configureBugsnag()
26
27 minioClient, err := createMinioClient()
28 if err != nil {
29 slog.Error("create minio client", "error", err)
30 bugsnag.Notify(err)
31 return
32 }
33
34 bucketName := os.Getenv("BUCKET_NAME")
35
36 err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{})
37 if err != nil {
38 slog.Error("create bucket", "error", err)
39 bugsnag.Notify(err)
40 return
41 }
42
43 backupPDS(ctx, minioClient, bucketName)
44}
45
46func createMinioClient() (*minio.Client, error) {
47 endpoint := os.Getenv("ENDPOINT")
48 accessKeyID := os.Getenv("ACCESS_ID")
49 secretAccessKey := os.Getenv("SECRET_ACCESS_KEY")
50 useSSL := true
51
52 return minio.New(endpoint, &minio.Options{
53 Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
54 Secure: useSSL,
55 })
56}
57
58func configureBugsnag() {
59 apiKey := os.Getenv("BUGSNAG_API_KEY")
60 if apiKey == "" {
61 slog.Info("bugsnag not configured")
62 return
63 }
64 bugsnag.Configure(bugsnag.Configuration{
65 APIKey: apiKey,
66 ReleaseStage: "production",
67 })
68}