|
|
@ -436,6 +436,7 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
# We're good but backups are even better!
|
|
|
|
# We're good but backups are even better!
|
|
|
|
@app.route("/backup", methods=['GET'])
|
|
|
|
@app.route("/backup", methods=['GET'])
|
|
|
|
def get_backup():
|
|
|
|
def get_backup():
|
|
|
|
|
|
|
|
|
|
|
|
import zipfile
|
|
|
|
import zipfile
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
@ -444,26 +445,30 @@ def changedetection_app(config=None, datastore_o=None):
|
|
|
|
|
|
|
|
|
|
|
|
# We only care about UUIDS from the current index file
|
|
|
|
# We only care about UUIDS from the current index file
|
|
|
|
uuids = list(datastore.data['watching'].keys())
|
|
|
|
uuids = list(datastore.data['watching'].keys())
|
|
|
|
|
|
|
|
backup_filepath = os.path.join(app.config['datastore_path'], backupname)
|
|
|
|
|
|
|
|
|
|
|
|
with zipfile.ZipFile(os.path.join(app.config['datastore_path'], backupname), 'w',
|
|
|
|
with zipfile.ZipFile(backup_filepath, "w",
|
|
|
|
compression=zipfile.ZIP_DEFLATED,
|
|
|
|
compression=zipfile.ZIP_DEFLATED,
|
|
|
|
compresslevel=6) as zipObj:
|
|
|
|
compresslevel=8) as zipObj:
|
|
|
|
|
|
|
|
|
|
|
|
# Be sure we're written fresh
|
|
|
|
# Be sure we're written fresh
|
|
|
|
datastore.sync_to_json()
|
|
|
|
datastore.sync_to_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.chdir(app.config['datastore_path'])
|
|
|
|
|
|
|
|
|
|
|
|
# Add the index
|
|
|
|
# Add the index
|
|
|
|
zipObj.write(os.path.join(app.config['datastore_path'], "url-watches.json"))
|
|
|
|
zipObj.write(os.path.join(app.config['datastore_path'], "url-watches.json"), arcname="url-watches.json")
|
|
|
|
# Add any snapshot data we find
|
|
|
|
|
|
|
|
|
|
|
|
# Add any snapshot data we find, use the full path to access the file, but make the file 'relative' in the Zip.
|
|
|
|
for txt_file_path in Path(app.config['datastore_path']).rglob('*.txt'):
|
|
|
|
for txt_file_path in Path(app.config['datastore_path']).rglob('*.txt'):
|
|
|
|
parent_p = txt_file_path.parent
|
|
|
|
parent_p = txt_file_path.parent
|
|
|
|
if parent_p.name in uuids:
|
|
|
|
if parent_p.name in uuids:
|
|
|
|
zipObj.write(txt_file_path)
|
|
|
|
zipObj.write(txt_file_path,
|
|
|
|
|
|
|
|
arcname=str(txt_file_path).replace(app.config['datastore_path'], ''),
|
|
|
|
|
|
|
|
compress_type=zipfile.ZIP_DEFLATED,
|
|
|
|
|
|
|
|
compresslevel=8)
|
|
|
|
|
|
|
|
|
|
|
|
return send_file(os.path.join(app.config['datastore_path'], backupname),
|
|
|
|
return send_from_directory(app.config['datastore_path'], backupname)
|
|
|
|
as_attachment=True,
|
|
|
|
|
|
|
|
mimetype="application/zip",
|
|
|
|
|
|
|
|
attachment_filename=backupname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/static/<string:group>/<string:filename>", methods=['GET'])
|
|
|
|
@app.route("/static/<string:group>/<string:filename>", methods=['GET'])
|
|
|
|
def static_content(group, filename):
|
|
|
|
def static_content(group, filename):
|
|
|
|