Files
minstrel/internal/db/migrations/0100_backup_music.up.sql
T
bvandeusenandClaude Opus 5.5 967763f6ce
release / govulncheck (push) Successful in 15s
release / web (push) Failing after 1m17s
release / go (push) Successful in 1m33s
release / integration (push) Successful in 5m16s
release / android (push) Successful in 5m56s
release / Build signed APK (push) Successful in 6m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
feat: the backup can include the music, sending each library file once to music/ and again only when it changes (#6774)
With "Include the music" on, each night's run sends the library files the
destination doesn't hold yet, after the database file has landed, for up to
six hours; a large library spans several nights the first time. Files keep
their path under the library folders' common root, beside database/ in the
same folder or bucket.

backup_music_files records each file's size and mtime as sent, so a night
sends only new and changed files, and a rescan that touches a track but finds
the same file sends nothing. A changed file goes to its old name; Minstrel
never deletes there. An object the bucket refuses (a locked overwrite) is
kept with its answer and goes again once the file changes or the settings are
saved; three refusals in a row stop the night's music, since that is a key
that may not write under music/. A folder copy is written under a .part name
and renamed, keeping the file's time.

The panel shows how much of the library is in, the refused files, and each
run's music count and note. The verdict still turns on the database file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 15:26:20 -05:00

37 lines
1.9 KiB
SQL

-- 0100_backup_music.up.sql — the music files in Minstrel's own backup.
--
-- Until now a backup held the database only. With include_music on, each
-- library file is also sent once to music/<path> in the same destination,
-- and sent again only when it changes.
--
-- backup_settings.include_music off until an admin switches it on.
-- backup_music_files one row per track sent (or refused): the
-- file's size and mtime when it was sent, so
-- a later night sends only what is new or
-- changed. A track the scan has touched since
-- checked_at is looked at again; it goes up
-- again only if the file itself changed, so a
-- full rescan doesn't resend the library. A
-- refusal is kept with its reason and tried
-- again once the file changes.
-- backup_runs.music_* how much a run sent, and why it stopped.
ALTER TABLE backup_settings ADD COLUMN include_music boolean NOT NULL DEFAULT false;
ALTER TABLE backup_runs
ADD COLUMN music_files integer NOT NULL DEFAULT 0,
ADD COLUMN music_bytes bigint NOT NULL DEFAULT 0,
ADD COLUMN music_note text NOT NULL DEFAULT '';
CREATE TABLE backup_music_files (
track_id uuid PRIMARY KEY REFERENCES tracks (id) ON DELETE CASCADE,
-- The file as it was sent.
size bigint NOT NULL,
mtime timestamptz NOT NULL,
-- Where it went: the object key, or the file's path in the folder.
location text NOT NULL,
-- When the file was last sent or found unchanged.
checked_at timestamptz NOT NULL DEFAULT now(),
-- Empty when it was sent; otherwise why the destination refused it.
error text NOT NULL DEFAULT ''
);