backup functionality to frontend and tasks

This commit is contained in:
simon 2021-09-16 18:16:09 +07:00
parent e53cfc5a32
commit c657baca97
4 changed files with 35 additions and 5 deletions

View File

@ -15,6 +15,7 @@ from home.src.download import (
) )
from home.src.config import AppConfig from home.src.config import AppConfig
from home.src.reindex import reindex_old_documents, ManualImport 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 from home.src.helper import get_lock
@ -93,3 +94,9 @@ def run_manual_import():
finally: finally:
if have_lock: if have_lock:
my_lock.release() my_lock.release()
@shared_task
def run_backup():
""" called from settings page, dump backup to zip file """
backup_all_indexes()
print('backup finished')

View File

@ -114,17 +114,24 @@
</div> </div>
<div class="settings-group"> <div class="settings-group">
<h2>Manual media files import.</h2> <h2>Manual media files import.</h2>
<p>Add files to the cache/import folder. Make sure to follow the instructions on <a href="https://github.com/bbilly1/tubearchivist#import-your-existing-library" target="_blank">Github</a>.</p> <p>Add files to the <span class="settings-current">cache/import</span> folder. Make sure to follow the instructions on <a href="https://github.com/bbilly1/tubearchivist#import-your-existing-library" target="_blank">Github</a>.</p>
<div id="manual-import"> <div id="manual-import">
<button onclick="manualImport()">Start import</button> <button onclick="manualImport()">Start import</button>
</div> </div>
</div> </div>
<div class="settings-group"> <div class="settings-group">
<p>Rescan filesystem.</p> <h2>Backup database</h2>
<p>Export your database to a zip file stored at <span class="settings-current">cache/backup</span>.</p>
<div id="db-backup">
<button onclick="dbBackup()">Start backup</button>
</div>
</div>
<div class="settings-group">
<p>Restore from backup.</p>
<i>Coming soon</i> <i>Coming soon</i>
</div> </div>
<div class="settings-group"> <div class="settings-group">
<p>Backup database.</p> <p>Rescan filesystem.</p>
<i>Coming soon</i> <i>Coming soon</i>
</div> </div>
{% endblock content %} {% endblock content %}

View File

@ -31,7 +31,8 @@ from home.tasks import (
download_pending, download_pending,
extrac_dl, extrac_dl,
download_single, download_single,
run_manual_import run_manual_import,
run_backup
) )
@ -442,7 +443,8 @@ class PostData:
VALID_KEYS = [ VALID_KEYS = [
"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"
] ]
def __init__(self, post_dict): def __init__(self, post_dict):
@ -514,6 +516,9 @@ class PostData:
elif task == 'manual-import': elif task == 'manual-import':
print('starting manual import') print('starting manual import')
run_manual_import.delay() run_manual_import.delay()
elif task == 'db-backup':
print('backing up database')
run_backup.delay()
return {'success': True} return {'success': True}
def search_channels(self, search_query): def search_channels(self, search_query):

View File

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