瀏覽代碼

Download attachments backup (#3663)

* [enhance] provision to download attachments backup

* [fix] enqueue files backup job if job not in queue
version-14
Saurabh 8 年之前
committed by Rushabh Mehta
父節點
當前提交
91415a6508
共有 4 個檔案被更改,包括 43 行新增2 行删除
  1. +7
    -0
      frappe/desk/page/backups/backups.js
  2. +28
    -1
      frappe/desk/page/backups/backups.py
  3. +6
    -0
      frappe/templates/emails/file_backup_notification.html
  4. +2
    -1
      frappe/utils/backups.py

+ 7
- 0
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"));


+ 28
- 1
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:]))

+ 6
- 0
frappe/templates/emails/file_backup_notification.html 查看文件

@@ -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>

+ 2
- 1
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__":


Loading…
取消
儲存