* [Minor] Allow user to set limit for downloadable backups for the site * [Fix] Updated path for daily_long and weekly_long dropbox backup hooks * [Fix] Updated system_settings.jsonversion-14
@@ -5,6 +5,10 @@ frappe.pages['backups'].on_page_load = function(wrapper) { | |||||
single_column: true | single_column: true | ||||
}); | }); | ||||
page.add_inner_button(__("Set Number of Backups"), function() { | |||||
frappe.set_route('Form', 'System Settings'); | |||||
}); | |||||
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,5 +1,6 @@ | |||||
import os | import os | ||||
from frappe.utils import get_site_path | |||||
import frappe | |||||
from frappe.utils import get_site_path, cint | |||||
from frappe.utils.data import convert_utc_to_user_timezone | from frappe.utils.data import convert_utc_to_user_timezone | ||||
import datetime | import datetime | ||||
@@ -17,9 +18,41 @@ def get_context(context): | |||||
path = get_site_path('private', 'backups') | path = get_site_path('private', 'backups') | ||||
files = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))] | files = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))] | ||||
backup_limit = get_scheduled_backup_limit() | |||||
if len(files) > backup_limit: | |||||
cleanup_old_backups(path, files, backup_limit) | |||||
files = [('/backups/' + _file, | files = [('/backups/' + _file, | ||||
get_time(os.path.join(path, _file)), | get_time(os.path.join(path, _file)), | ||||
get_size(os.path.join(path, _file))) for _file in files] | get_size(os.path.join(path, _file))) for _file in files] | ||||
files.sort(key=lambda x: x[1], reverse=True) | files.sort(key=lambda x: x[1], reverse=True) | ||||
return {"files": files} | return {"files": files} | ||||
def get_scheduled_backup_limit(): | |||||
backup_limit = frappe.db.get_singles_value('System Settings', 'backup_limit') | |||||
return cint(backup_limit) | |||||
def cleanup_old_backups(site_path, files, limit): | |||||
backup_paths = [] | |||||
for f in files: | |||||
_path = os.path.abspath(os.path.join(site_path, f)) | |||||
backup_paths.append(_path) | |||||
backup_paths = sorted(backup_paths, key=os.path.getctime) | |||||
files_to_delete = len(backup_paths) - limit | |||||
for idx in range(0, files_to_delete): | |||||
f = os.path.basename(backup_paths[idx]) | |||||
files.remove(f) | |||||
os.remove(backup_paths[idx]) | |||||
def delete_downloadable_backups(): | |||||
path = get_site_path('private', 'backups') | |||||
files = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))] | |||||
backup_limit = get_scheduled_backup_limit() | |||||
if len(files) > backup_limit: | |||||
cleanup_old_backups(path, files, backup_limit) |
@@ -72,6 +72,7 @@ def update_system_settings(args): | |||||
'date_format': frappe.db.get_value("Country", args.get("country"), "date_format"), | 'date_format': frappe.db.get_value("Country", args.get("country"), "date_format"), | ||||
'number_format': number_format, | 'number_format': number_format, | ||||
'enable_scheduler': 1 if not frappe.flags.in_test else 0, | 'enable_scheduler': 1 if not frappe.flags.in_test else 0, | ||||
'backup_limit': 3 # Default for downloadable backups | |||||
}) | }) | ||||
system_settings.save() | system_settings.save() | ||||
@@ -235,4 +236,4 @@ def email_setup_wizard_exception(traceback, args): | |||||
delayed=False) | delayed=False) | ||||
def get_language_code(lang): | def get_language_code(lang): | ||||
return frappe.db.get_value('Language', {'language_name':lang}) | |||||
return frappe.db.get_value('Language', {'language_name':lang}) |
@@ -143,13 +143,14 @@ scheduler_events = { | |||||
"frappe.utils.scheduler.disable_scheduler_on_expiry", | "frappe.utils.scheduler.disable_scheduler_on_expiry", | ||||
"frappe.utils.scheduler.restrict_scheduler_events_if_dormant", | "frappe.utils.scheduler.restrict_scheduler_events_if_dormant", | ||||
"frappe.limits.update_space_usage", | "frappe.limits.update_space_usage", | ||||
"frappe.email.doctype.auto_email_report.auto_email_report.send_daily" | |||||
"frappe.email.doctype.auto_email_report.auto_email_report.send_daily", | |||||
"frappe.desk.page.backups.backups.delete_downloadable_backups" | |||||
], | ], | ||||
"daily_long": [ | "daily_long": [ | ||||
"frappe.integrations.doctype.dropbox_backup.dropbox_backup.take_backups_daily" | |||||
"frappe.integrations.dropbox_integration.take_backups_daily" | |||||
], | ], | ||||
"weekly_long": [ | "weekly_long": [ | ||||
"frappe.integrations.doctype.dropbox_backup.dropbox_backup.take_backups_weekly" | |||||
"frappe.integrations.dropbox_integration.take_backups_weekly" | |||||
], | ], | ||||
"monthly": [ | "monthly": [ | ||||
"frappe.email.doctype.auto_email_report.auto_email_report.send_monthly" | "frappe.email.doctype.auto_email_report.auto_email_report.send_monthly" | ||||
@@ -187,4 +188,4 @@ setup_wizard_exception = "frappe.desk.page.setup_wizard.setup_wizard.email_setup | |||||
before_write_file = "frappe.limits.validate_space_limit" | before_write_file = "frappe.limits.validate_space_limit" | ||||
integration_services = ["PayPal", "Razorpay", "Dropbox Integration", "LDAP Auth"] | |||||
integration_services = ["PayPal", "Razorpay", "Dropbox Integration", "LDAP Auth"] |