Add database backup functionality
This commit is contained in:
@@ -28,6 +28,15 @@
|
||||
<a class={["max-sm:hidden" | nav_link_classes()]} } href={~p"/dev/errors"}>
|
||||
{gettext("Errors")}
|
||||
</a>
|
||||
<a class={nav_link_classes()} } href={~p"/backup"}>
|
||||
<.icon
|
||||
name="hero-archive-box-arrow-down"
|
||||
class="h-4 w-4 mr-2"
|
||||
aria-hidden="true"
|
||||
data-slot="icon"
|
||||
/>
|
||||
{gettext("Backup")}
|
||||
</a>
|
||||
<a class={nav_link_classes()} } href={~p"/login"}>
|
||||
<.icon
|
||||
name="hero-arrow-left-start-on-rectangle"
|
||||
|
||||
@@ -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
|
||||
@@ -31,6 +31,8 @@ defmodule MusicLibraryWeb.Router do
|
||||
scope "/" do
|
||||
pipe_through :logged_in
|
||||
|
||||
get "/backup", ArchiveController, :backup
|
||||
|
||||
get "/covers/:record_id", CoverController, :show
|
||||
|
||||
live "/", StatsLive.Index, :index
|
||||
|
||||
@@ -123,7 +123,7 @@ msgstr ""
|
||||
msgid "Login"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/layouts/app.html.heex:38
|
||||
#: lib/music_library_web/components/layouts/app.html.heex:47
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Logout"
|
||||
msgstr ""
|
||||
@@ -550,6 +550,7 @@ msgstr ""
|
||||
msgid "Album"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/layouts/app.html.heex:38
|
||||
#: lib/music_library_web/components/record_components.ex:213
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Backup"
|
||||
|
||||
Reference in New Issue
Block a user