added restore_from_backup to frontend and task

This commit is contained in:
simon 2021-09-20 20:26:28 +07:00
parent c17e2e6dd1
commit 1c3ca8364c
5 changed files with 36 additions and 5 deletions

View File

@ -10,7 +10,7 @@ from celery import Celery, shared_task
from home.src.config import AppConfig from home.src.config import AppConfig
from home.src.download import ChannelSubscription, PendingList, VideoDownloader from home.src.download import ChannelSubscription, PendingList, VideoDownloader
from home.src.helper import get_lock 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 from home.src.reindex import ManualImport, reindex_old_documents
CONFIG = AppConfig().config CONFIG = AppConfig().config
@ -94,3 +94,10 @@ def run_backup():
""" called from settings page, dump backup to zip file """ """ called from settings page, dump backup to zip file """
backup_all_indexes() backup_all_indexes()
print('backup finished') 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')

View File

@ -127,8 +127,12 @@
</div> </div>
</div> </div>
<div class="settings-group"> <div class="settings-group">
<p>Restore from backup.</p> <h2>Restore from backup</h2>
<i>Coming soon</i> <p><span class="danger-zone">Danger Zone</span>: This will replace your existing index with the backup.</p>
<p>Add the backup zip file to the <span class="settings-current">cache/backup</span> folder.</p>
<div id="db-restore">
<button onclick="dbRestore()">Restore backup</button>
</div>
</div> </div>
<div class="settings-group"> <div class="settings-group">
<p>Rescan filesystem.</p> <p>Rescan filesystem.</p>

View File

@ -20,7 +20,8 @@ from home.src.helper import (get_dl_message, get_message, process_url_list,
set_message) set_message)
from home.src.searching import Pagination, SearchHandler from home.src.searching import Pagination, SearchHandler
from home.tasks import (download_pending, download_single, extrac_dl, 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): class HomeView(View):
@ -461,7 +462,7 @@ class PostData:
"watched", "rescan_pending", "ignore", "dl_pending", "watched", "rescan_pending", "ignore", "dl_pending",
"unsubscribe", "sort_order", "hide_watched", "show_subed_only", "unsubscribe", "sort_order", "hide_watched", "show_subed_only",
"channel-search", "video-search", "dlnow", "manual-import", "channel-search", "video-search", "dlnow", "manual-import",
"db-backup" "db-backup", "db-restore"
] ]
def __init__(self, post_dict): def __init__(self, post_dict):
@ -536,6 +537,9 @@ class PostData:
elif task == 'db-backup': elif task == 'db-backup':
print('backing up database') print('backing up database')
run_backup.delay() run_backup.delay()
elif task == 'db-restore':
print('restoring index from backup zip')
run_restore_backup.delay()
return {'success': True} return {'success': True}
def search_channels(self, search_query): def search_channels(self, search_query):

View File

@ -493,6 +493,11 @@ button:hover {
min-width: 300px; min-width: 300px;
} }
.danger-zone {
background-color: var(--highlight-error);
padding: 3px;
}
/* about */ /* about */
.about-section { .about-section {
padding: 20px 0; padding: 20px 0;

View File

@ -102,6 +102,17 @@ function dbBackup() {
toReplace.appendChild(message); 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 // player
function createPlayer(button) { function createPlayer(button) {
var mediaUrl = button.getAttribute('data-src'); var mediaUrl = button.getAttribute('data-src');