1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added backup from web interface

This commit is contained in:
krateng 2021-12-26 20:53:38 +01:00
parent 03e741c0ae
commit af569ae983
3 changed files with 31 additions and 4 deletions

View File

@ -4,7 +4,7 @@ from ..__pkginfo__ import VERSION, VERSIONSTR
from ..malojauri import uri_to_internal
from .. import utilities
from bottle import response
from bottle import response, static_file
# nimrodel API
from nimrodel import EAPI as API
@ -335,5 +335,16 @@ def set_settings(**keys):
@api.post("apikeys")
@authenticated_api
def set_settings(**keys):
def set_apikeys(**keys):
apikeystore.update(keys)
@api.get("backup")
@authenticated_api
def get_backup(**keys):
from ..proccontrol.tasks.backup import backup
import tempfile
tmpfolder = tempfile.gettempdir()
archivefile = backup(tmpfolder)
return static_file(os.path.basename(archivefile),root=tmpfolder)

View File

@ -14,14 +14,13 @@ user_files = {
"scrobbles":["*.tsv"]
},
"full":{
"clients":["authenticated_machines.tsv"],
"clients":["apikeys.yml"],
"images":["artists","tracks"],
"settings":["settings.ini"]
}
}
def backup(folder,level="full"):
print(folder)
selected_files = user_files["minimal"] if level == "minimal" else {**user_files["minimal"], **user_files["full"]}
real_files = {cat:[] for cat in selected_files}
@ -45,3 +44,4 @@ def backup(folder,level="full"):
r = p.relative_to(data_dir[cat]())
archive.add(f,arcname=os.path.join(cat,r))
log("Backup created!")
return archivefile

View File

@ -75,11 +75,27 @@
<button type="button" id="adminmodebutton" onclick="activate()">Activate</button>
{% endif %}
<h2>Download Data</h2>
Download your data to store local backups.<br/><br/>
<a href="/apis/mlj_1/backup" download="maloja_backup.tar.gz">
<button type="button">Download Backup</button>
</a>
<h2>Links</h2>
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja/issues/new">Report Issue</a><br/>
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://github.com/krateng/maloja/blob/master/README.md">Readme</a><br/>
<a class="textlink" target="_blank" rel="noopener noreferrer" href="https://pypi.org/project/malojaserver/">PyPi</a><br/>
{% if false %}
<h2>Change Password</h2>