Files
backup-tool/main.go

44 lines
887 B
Go

package main
import (
"backup-tool/s3helper"
"context"
"fmt"
"log"
"os"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatalf("error loading .env file: (%s)", err.Error())
}
if len(os.Args) > 1 {
// only do this if we have been given a file to upload (for now)
// TODO: have this tool take the backup of the DB itself
b2Creds, err := getCredentials([]string{"B2_KEY_ID", "B2_APPLICATION_KEY"})
if err != nil {
log.Fatalf("could not get B2 credentials: %s", err)
}
s3helper.UploadFile(context.Background(), b2Creds)
}
}
func getCredentials(credNames []string) (map[string]string, error) {
creds := map[string]string{}
for _, name := range credNames {
value := os.Getenv(name)
if value == "" {
return nil, fmt.Errorf("missing or empty ENV var: %s", name)
}
creds[name] = value
}
return creds, nil
}