Improvements for backup (#70)

* Remove previous backup files

* Backup - Add a text file containing only the URLs, with Windows+UNIX line-endings, for better portability.

* Fix filename on backup not being correct
pull/72/head
dgtlmoon 4 years ago committed by GitHub
parent 13de31cf98
commit d4f3e744de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -633,6 +633,10 @@ def changedetection_app(conig=None, datastore_o=None):
import zipfile import zipfile
from pathlib import Path from pathlib import Path
# Remove any existing backup file, for now we just keep one file
for previous_backup_filename in Path(app.config['datastore_path']).rglob('changedetection-backup-*.zip'):
os.unlink(previous_backup_filename)
# create a ZipFile object # create a ZipFile object
backupname = "changedetection-backup-{}.zip".format(int(time.time())) backupname = "changedetection-backup-{}.zip".format(int(time.time()))
@ -662,7 +666,20 @@ def changedetection_app(conig=None, datastore_o=None):
compress_type=zipfile.ZIP_DEFLATED, compress_type=zipfile.ZIP_DEFLATED,
compresslevel=8) compresslevel=8)
return send_from_directory(app.config['datastore_path'], backupname) # Create a list file with just the URLs, so it's easier to port somewhere else in the future
list_file = os.path.join(app.config['datastore_path'], "url-list.txt")
with open(list_file, "w") as f:
for uuid in datastore.data['watching']:
url = datastore.data['watching'][uuid]['url']
f.write("{}\r\n".format(url))
# Add it to the Zip
zipObj.write(list_file,
arcname="url-list.txt",
compress_type=zipfile.ZIP_DEFLATED,
compresslevel=8)
return send_from_directory(app.config['datastore_path'], backupname, as_attachment=True)
@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):

Loading…
Cancel
Save