* [enhance] provision to download attachments backup * [fix] enqueue files backup job if job not in queueversion-14
@@ -9,6 +9,13 @@ frappe.pages['backups'].on_page_load = function(wrapper) { | |||||
frappe.set_route('Form', 'System Settings'); | frappe.set_route('Form', 'System Settings'); | ||||
}); | }); | ||||
page.add_inner_button(__("Download Files Backup"), function () { | |||||
frappe.call({ | |||||
method:"frappe.desk.page.backups.backups.schedule_files_backup", | |||||
args: {"user_email": frappe.session.user_email} | |||||
}); | |||||
}); | |||||
frappe.breadcrumbs.add("Setup"); | frappe.breadcrumbs.add("Setup"); | ||||
$(frappe.render_template("backups")).appendTo(page.body.addClass("no-border")); | $(frappe.render_template("backups")).appendTo(page.body.addClass("no-border")); | ||||
@@ -1,6 +1,7 @@ | |||||
import os | import os | ||||
import frappe | import frappe | ||||
from frappe.utils import get_site_path, cint | |||||
from frappe import _ | |||||
from frappe.utils import get_site_path, cint, get_url | |||||
from frappe.utils.data import convert_utc_to_user_timezone | from frappe.utils.data import convert_utc_to_user_timezone | ||||
import datetime | import datetime | ||||
@@ -57,3 +58,29 @@ def delete_downloadable_backups(): | |||||
if len(files) > backup_limit: | if len(files) > backup_limit: | ||||
cleanup_old_backups(path, files, backup_limit) | cleanup_old_backups(path, files, backup_limit) | ||||
@frappe.whitelist() | |||||
def schedule_files_backup(user_email): | |||||
from frappe.utils.background_jobs import enqueue, get_jobs | |||||
queued_jobs = get_jobs(site=frappe.local.site, queue="long") | |||||
method = 'frappe.desk.page.backups.backups.backup_files_and_notify_user' | |||||
if method not in queued_jobs[frappe.local.site]: | |||||
enqueue("frappe.desk.page.backups.backups.backup_files_and_notify_user", queue='long', user_email=user_email) | |||||
frappe.msgprint(_("Queued for backup. You will receive an email with the download link")) | |||||
else: | |||||
frappe.msgprint(_("Backup job is already queued. You will receive an email with the download link")) | |||||
def backup_files_and_notify_user(user_email=None): | |||||
from frappe.utils.backups import backup | |||||
backup_files = backup(with_files=True) | |||||
get_downloadable_links(backup_files) | |||||
subject = "File backup is ready" | |||||
message = frappe.render_template('frappe/templates/emails/file_backup_notification.html', backup_files, is_path=True) | |||||
frappe.sendmail(recipients=[user_email], subject=subject, message=message) | |||||
def get_downloadable_links(backup_files): | |||||
for key in ['backup_path_files', 'backup_path_private_files']: | |||||
path = backup_files[key] | |||||
backup_files[key] = get_url('/'.join(path.split('/')[-2:])) |
@@ -0,0 +1,6 @@ | |||||
Hello, | |||||
<br> | |||||
<p> Please use following links to download file backup. </p> | |||||
<p> Public Files Backup: <a href='{{ backup_path_files }}'>{{ backup_path_files }}</a> </p> | |||||
<p> Private Files Backup: <a href='{{ backup_path_private_files }}'>{{ backup_path_private_files }}</a> </p> |
@@ -217,7 +217,8 @@ def backup(with_files=False, backup_path_db=None, backup_path_files=None, quiet= | |||||
odb = scheduled_backup(ignore_files=not with_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files, force=True) | odb = scheduled_backup(ignore_files=not with_files, backup_path_db=backup_path_db, backup_path_files=backup_path_files, force=True) | ||||
return { | return { | ||||
"backup_path_db": odb.backup_path_db, | "backup_path_db": odb.backup_path_db, | ||||
"backup_path_files": odb.backup_path_files | |||||
"backup_path_files": odb.backup_path_files, | |||||
"backup_path_private_files": odb.backup_path_private_files | |||||
} | } | ||||
if __name__ == "__main__": | if __name__ == "__main__": | ||||