diff --git a/frappe/desk/page/backups/backups.js b/frappe/desk/page/backups/backups.js index c42819aba1..c82407c6bd 100644 --- a/frappe/desk/page/backups/backups.js +++ b/frappe/desk/page/backups/backups.js @@ -9,6 +9,13 @@ frappe.pages['backups'].on_page_load = function(wrapper) { 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.render_template("backups")).appendTo(page.body.addClass("no-border")); diff --git a/frappe/desk/page/backups/backups.py b/frappe/desk/page/backups/backups.py index 145693972c..f3517c6953 100644 --- a/frappe/desk/page/backups/backups.py +++ b/frappe/desk/page/backups/backups.py @@ -1,6 +1,7 @@ import os 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 import datetime @@ -57,3 +58,29 @@ def delete_downloadable_backups(): if len(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:])) \ No newline at end of file diff --git a/frappe/templates/emails/file_backup_notification.html b/frappe/templates/emails/file_backup_notification.html new file mode 100644 index 0000000000..7528e93570 --- /dev/null +++ b/frappe/templates/emails/file_backup_notification.html @@ -0,0 +1,6 @@ +Hello, + +
+

Please use following links to download file backup.

+

Public Files Backup: {{ backup_path_files }}

+

Private Files Backup: {{ backup_path_private_files }}

diff --git a/frappe/utils/backups.py b/frappe/utils/backups.py index 3bebd62a7a..d3a7b74ac4 100644 --- a/frappe/utils/backups.py +++ b/frappe/utils/backups.py @@ -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) return { "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__":