Files
music_library/lib/music_library_web/controllers/archive_controller.ex
T
2025-10-25 11:36:34 +01:00

21 lines
526 B
Elixir

defmodule MusicLibraryWeb.ArchiveController do
use MusicLibraryWeb, :controller
def backup(conn, _params) do
MusicLibrary.Repo.vacuum()
database_path = database_path()
current_time = DateTime.utc_now()
file_name = "music_library_#{DateTime.to_unix(current_time)}.db"
send_download(conn, {:file, database_path},
filename: file_name,
content_type: "application/x-sqlite3"
)
end
defp database_path do
Application.get_env(:music_library, MusicLibrary.Repo)[:database]
end
end