cluster

Infrastructure files for Nordgedanken and Midnightthoughts.
git clone git://archive.git.mtrnord.blog/MTRNord/cluster.git
Log | Files | Refs | README

main.go (1397B)


      1 // matrix-backup pulls E2EE key backups, room history, and media from a Matrix
      2 // homeserver and stores them in S3. Accounts are configured via environment
      3 // variables; see the deployment CronJob manifest for the full list.
      4 //
      5 // Room history is decrypted using the Megolm sessions fetched from the
      6 // server-side key backup, then re-encrypted with age before uploading to S3.
      7 // Session tokens and the device crypto store are persisted as a tarball in S3
      8 // so incremental sync works across CronJob runs.
      9 //
     10 // Build: CGO_ENABLED=0 go build -tags goolm -o matrix-backup .
     11 package main
     12 
     13 import (
     14 	"context"
     15 	"log/slog"
     16 	"os"
     17 )
     18 
     19 func main() {
     20 	slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
     21 		Level: slog.LevelInfo,
     22 	})))
     23 
     24 	ctx := context.Background()
     25 
     26 	if err := initAgeRecipients(mustEnv("AGE_RECIPIENTS")); err != nil {
     27 		slog.Error("Failed to init age recipients", "error", err)
     28 		os.Exit(1)
     29 	}
     30 
     31 	if err := initAgeIdentity(os.Getenv("AGE_PRIVATE_KEY")); err != nil {
     32 		slog.Error("Failed to init age identity", "error", err)
     33 		os.Exit(1)
     34 	}
     35 
     36 	if err := initS3(ctx); err != nil {
     37 		slog.Error("Failed to init S3", "error", err)
     38 		os.Exit(1)
     39 	}
     40 
     41 	for _, acc := range accounts {
     42 		if err := backupAccount(ctx, acc); err != nil {
     43 			slog.Error("Account backup failed", "user_id", acc.UserID, "error", err)
     44 		}
     45 	}
     46 
     47 	slog.Info("All accounts backed up successfully")
     48 }