From 1c3ca8364c7e50623e8efc3871cf55d4690cd4e5 Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 20 Sep 2021 20:26:28 +0700 Subject: [PATCH] added restore_from_backup to frontend and task --- tubearchivist/home/tasks.py | 9 ++++++++- tubearchivist/home/templates/home/settings.html | 8 ++++++-- tubearchivist/home/views.py | 8 ++++++-- tubearchivist/static/css/style.css | 5 +++++ tubearchivist/static/script.js | 11 +++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 17f9a67..5b19b9f 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -10,7 +10,7 @@ from celery import Celery, shared_task from home.src.config import AppConfig from home.src.download import ChannelSubscription, PendingList, VideoDownloader from home.src.helper import get_lock -from home.src.index_management import backup_all_indexes +from home.src.index_management import backup_all_indexes, restore_from_backup from home.src.reindex import ManualImport, reindex_old_documents CONFIG = AppConfig().config @@ -94,3 +94,10 @@ def run_backup(): """ called from settings page, dump backup to zip file """ backup_all_indexes() print('backup finished') + + +@shared_task +def run_restore_backup(): + """ called from settings page, dump backup to zip file """ + restore_from_backup() + print('index restore finished') diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index c4fba21..8199656 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -127,8 +127,12 @@
-

Restore from backup.

- Coming soon +

Restore from backup

+

Danger Zone: This will replace your existing index with the backup.

+

Add the backup zip file to the cache/backup folder.

+
+ +

Rescan filesystem.

diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index d0231b4..d107a10 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -20,7 +20,8 @@ from home.src.helper import (get_dl_message, get_message, process_url_list, set_message) from home.src.searching import Pagination, SearchHandler from home.tasks import (download_pending, download_single, extrac_dl, - run_backup, run_manual_import, update_subscribed) + run_backup, run_manual_import, run_restore_backup, + update_subscribed) class HomeView(View): @@ -461,7 +462,7 @@ class PostData: "watched", "rescan_pending", "ignore", "dl_pending", "unsubscribe", "sort_order", "hide_watched", "show_subed_only", "channel-search", "video-search", "dlnow", "manual-import", - "db-backup" + "db-backup", "db-restore" ] def __init__(self, post_dict): @@ -536,6 +537,9 @@ class PostData: elif task == 'db-backup': print('backing up database') run_backup.delay() + elif task == 'db-restore': + print('restoring index from backup zip') + run_restore_backup.delay() return {'success': True} def search_channels(self, search_query): diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 2762a31..1bcbc59 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -493,6 +493,11 @@ button:hover { min-width: 300px; } +.danger-zone { + background-color: var(--highlight-error); + padding: 3px; +} + /* about */ .about-section { padding: 20px 0; diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 94b5172..c726035 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -102,6 +102,17 @@ function dbBackup() { toReplace.appendChild(message); } +function dbRestore() { + var payload = JSON.stringify({'db-restore': true}); + sendPost(payload) + // clear button + var message = document.createElement('p'); + message.innerText = 'restoring from backup'; + var toReplace = document.getElementById('db-restore'); + toReplace.innerHTML = ''; + toReplace.appendChild(message); +} + // player function createPlayer(button) { var mediaUrl = button.getAttribute('data-src');