From c657baca97918de4c314d5f9d21a894d93f97b32 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 16 Sep 2021 18:16:09 +0700 Subject: [PATCH] backup functionality to frontend and tasks --- tubearchivist/home/tasks.py | 7 +++++++ tubearchivist/home/templates/home/settings.html | 13 ++++++++++--- tubearchivist/home/views.py | 9 +++++++-- tubearchivist/static/script.js | 11 +++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index b24751c..321b5b5 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -15,6 +15,7 @@ from home.src.download import ( ) from home.src.config import AppConfig from home.src.reindex import reindex_old_documents, ManualImport +from home.src.index_management import backup_all_indexes from home.src.helper import get_lock @@ -93,3 +94,9 @@ def run_manual_import(): finally: if have_lock: my_lock.release() + +@shared_task +def run_backup(): + """ called from settings page, dump backup to zip file """ + backup_all_indexes() + print('backup finished') diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 2fddf3d..79c11d1 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -114,17 +114,24 @@

Manual media files import.

-

Add files to the cache/import folder. Make sure to follow the instructions on Github.

+

Add files to the cache/import folder. Make sure to follow the instructions on Github.

-

Rescan filesystem.

+

Backup database

+

Export your database to a zip file stored at cache/backup.

+
+ +
+
+
+

Restore from backup.

Coming soon
-

Backup database.

+

Rescan filesystem.

Coming soon
{% endblock content %} \ No newline at end of file diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 5768c83..a781c9a 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -31,7 +31,8 @@ from home.tasks import ( download_pending, extrac_dl, download_single, - run_manual_import + run_manual_import, + run_backup ) @@ -442,7 +443,8 @@ class PostData: VALID_KEYS = [ "watched", "rescan_pending", "ignore", "dl_pending", "unsubscribe", "sort_order", "hide_watched", "show_subed_only", - "channel-search", "video-search", "dlnow", "manual-import" + "channel-search", "video-search", "dlnow", "manual-import", + "db-backup" ] def __init__(self, post_dict): @@ -514,6 +516,9 @@ class PostData: elif task == 'manual-import': print('starting manual import') run_manual_import.delay() + elif task == 'db-backup': + print('backing up database') + run_backup.delay() return {'success': True} def search_channels(self, search_query): diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 05a9816..3d4b0fe 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -91,6 +91,17 @@ function manualImport() { toReplace.appendChild(message); } +function dbBackup() { + var payload = JSON.stringify({'db-backup': true}); + sendPost(payload) + // clear button + var message = document.createElement('p'); + message.innerText = 'backing up archive'; + var toReplace = document.getElementById('db-backup'); + toReplace.innerHTML = ''; + toReplace.appendChild(message); +} + // player function createPlayer(button) { var mediaUrl = button.getAttribute('data-src');