Add database backup functionality

This commit is contained in:
Claudio Ortolina
2025-01-30 09:39:45 +00:00
parent 441bfcb9ef
commit b47f282223
4 changed files with 31 additions and 1 deletions
@@ -0,0 +1,18 @@
defmodule MusicLibraryWeb.ArchiveController do
use MusicLibraryWeb, :controller
def backup(conn, _params) do
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