release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.7 KiB
Go
77 lines
2.7 KiB
Go
package main
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"flag"
|
||
"fmt"
|
||
"io"
|
||
"os"
|
||
|
||
"github.com/Fabled-Sword/minstrel/internal/backup"
|
||
"github.com/Fabled-Sword/minstrel/internal/config"
|
||
"github.com/Fabled-Sword/minstrel/internal/db"
|
||
"github.com/Fabled-Sword/minstrel/internal/logging"
|
||
)
|
||
|
||
const restoreUsage = "usage: minstrel restore [-config PATH] FILE"
|
||
|
||
// runRestore loads a backup file into a new Minstrel's database: one with no
|
||
// accounts and no library yet. It brings the schema up to date first, so a
|
||
// backup from an older Minstrel loads into this one. The server isn't running
|
||
// meanwhile, so the library scan waits for it to start.
|
||
func runRestore(args []string) error {
|
||
fs := flag.NewFlagSet("restore", flag.ContinueOnError)
|
||
configPath := fs.String("config", os.Getenv("MINSTREL_CONFIG"), "path to YAML config file")
|
||
if err := fs.Parse(args); err != nil {
|
||
return err
|
||
}
|
||
if fs.NArg() != 1 {
|
||
return errors.New(restoreUsage)
|
||
}
|
||
cfg, err := config.Load(*configPath)
|
||
if err != nil {
|
||
return fmt.Errorf("load config: %w", err)
|
||
}
|
||
if cfg.Database.URL == "" {
|
||
return errors.New("no database URL configured (set it in the config file or MINSTREL_DATABASE_URL)")
|
||
}
|
||
logger, err := logging.New(os.Stderr, cfg.Log.Level, cfg.Log.Format)
|
||
if err != nil {
|
||
return fmt.Errorf("init logger: %w", err)
|
||
}
|
||
|
||
f, err := os.Open(fs.Arg(0))
|
||
if err != nil {
|
||
return err
|
||
}
|
||
defer func() { _ = f.Close() }()
|
||
manifest, contents, err := backup.Read(f)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if err := db.Migrate(cfg.Database.URL, logger); err != nil {
|
||
return fmt.Errorf("migrate: %w", err)
|
||
}
|
||
ctx := context.Background()
|
||
pool, err := db.Open(ctx, cfg.Database.URL)
|
||
if err != nil {
|
||
return fmt.Errorf("open db: %w", err)
|
||
}
|
||
defer pool.Close()
|
||
if err := backup.Restore(ctx, pool, contents); err != nil {
|
||
return err
|
||
}
|
||
printRestored(os.Stdout, manifest)
|
||
return nil
|
||
}
|
||
|
||
// printRestored says what came back and what happens next.
|
||
func printRestored(w io.Writer, m backup.Manifest) {
|
||
_, _ = fmt.Fprintf(w, "minstrel: restored the backup made %s by Minstrel %s (%d accounts, %d tracks, %d playlists).\n",
|
||
m.CreatedAt.Local().Format("2 Jan 2006 15:04 MST"), m.Build,
|
||
m.Rows["users"], m.Rows["tracks"], m.Rows["playlists"])
|
||
_, _ = fmt.Fprintln(w, "Start the server. The library scan (at startup, or Scan now under Admin › Library) finds each music file at its path, and the artwork, tags and analysis the backup leaves out are fetched and worked out again.")
|
||
_, _ = fmt.Fprintln(w, "Everyone signs in with the password they had. Subsonic apps are signed out: each person makes a new Subsonic password in their own Settings, and saves their ListenBrainz token there again. Keys for other services, and the backup's own destination, are entered again in Admin.")
|
||
}
|