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("S3_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 backupTangledKnot(ctx, minioClient, bucketName)
45}
46
47func createMinioClient() (*minio.Client, error) {
48 endpoint := os.Getenv("S3_ENDPOINT")
49 accessKeyID := os.Getenv("S3_ACCESS_ID")
50 secretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY")
51 useSSL := true
52
53 return minio.New(endpoint, &minio.Options{
54 Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
55 Secure: useSSL,
56 })
57}
58
59func configureBugsnag() {
60 apiKey := os.Getenv("BUGSNAG_API_KEY")
61 if apiKey == "" {
62 slog.Info("bugsnag not configured")
63 return
64 }
65 bugsnag.Configure(bugsnag.Configuration{
66 APIKey: apiKey,
67 ReleaseStage: "production",
68 })
69}