kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Easily download a full backup
rodzic
c4197a5045
commit
26c9a6e0fc
|
@ -255,6 +255,36 @@ def favicon():
|
||||||
return send_from_directory("/app/static/images", filename="favicon.ico")
|
return send_from_directory("/app/static/images", filename="favicon.ico")
|
||||||
|
|
||||||
|
|
||||||
|
# We're good but backups are even better!
|
||||||
|
@app.route("/backup", methods=['GET'])
|
||||||
|
def get_backup():
|
||||||
|
import zipfile
|
||||||
|
from pathlib import Path
|
||||||
|
import zlib
|
||||||
|
|
||||||
|
# create a ZipFile object
|
||||||
|
backupname = "changedetection-backup-{}.zip".format(int(time.time()))
|
||||||
|
|
||||||
|
# We only care about UUIDS from the current index file
|
||||||
|
uuids = list(datastore.data['watching'].keys())
|
||||||
|
|
||||||
|
with zipfile.ZipFile(os.path.join("/datastore", backupname), 'w', compression=zipfile.ZIP_DEFLATED,
|
||||||
|
compresslevel=6) as zipObj:
|
||||||
|
# Add the index
|
||||||
|
zipObj.write(os.path.join("/datastore", "url-watches.json"))
|
||||||
|
# Add any snapshot data we find
|
||||||
|
for txt_file_path in Path('/datastore').rglob('*.txt'):
|
||||||
|
parent_p = txt_file_path.parent
|
||||||
|
if parent_p.name in uuids:
|
||||||
|
zipObj.write(txt_file_path)
|
||||||
|
|
||||||
|
return send_file(os.path.join("/datastore", backupname),
|
||||||
|
as_attachment=True,
|
||||||
|
mimetype="application/zip",
|
||||||
|
attachment_filename=backupname)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# A few self sanity checks, mostly for developer/bug check
|
# A few self sanity checks, mostly for developer/bug check
|
||||||
@app.route("/self-check", methods=['GET'])
|
@app.route("/self-check", methods=['GET'])
|
||||||
def selfcheck():
|
def selfcheck():
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
<ul class="pure-menu-list">
|
<ul class="pure-menu-list">
|
||||||
|
|
||||||
|
<li class="pure-menu-item">
|
||||||
|
<a href="/backup" class="pure-menu-link">BACKUP</a>
|
||||||
|
</li>
|
||||||
<li class="pure-menu-item">
|
<li class="pure-menu-item">
|
||||||
<a href="/import" class="pure-menu-link">IMPORT</a>
|
<a href="/import" class="pure-menu-link">IMPORT</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Ładowanie…
Reference in New Issue