[enhancement] list backups for download
This commit is contained in:
parent
1568dc32a2
commit
306c49f8a0
@ -158,3 +158,4 @@ erpnext.patches.v5_0.update_tax_amount_after_discount_in_purchase_cycle
|
|||||||
erpnext.patches.v5_0.rename_pos_setting
|
erpnext.patches.v5_0.rename_pos_setting
|
||||||
erpnext.patches.v5_0.update_operation_description
|
erpnext.patches.v5_0.update_operation_description
|
||||||
erpnext.patches.v5_0.set_footer_address
|
erpnext.patches.v5_0.set_footer_address
|
||||||
|
execute:frappe.db.set_value("Backup Manager", None, "send_backups_to_dropbox", 1 if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox") in ("Daily", "Weekly") else 0)
|
||||||
|
@ -48,6 +48,7 @@ def dropbox_callback(oauth_token=None, not_approved=False):
|
|||||||
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_key", access_token.key)
|
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_key", access_token.key)
|
||||||
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_secret", access_token.secret)
|
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_secret", access_token.secret)
|
||||||
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_allowed", allowed)
|
frappe.db.set_value("Backup Manager", "Backup Manager", "dropbox_access_allowed", allowed)
|
||||||
|
frappe.db.set_value("Backup Manager", "Backup Manager", "send_backups_to_dropbox", 1)
|
||||||
dropbox_client = client.DropboxClient(sess)
|
dropbox_client = client.DropboxClient(sess)
|
||||||
try:
|
try:
|
||||||
dropbox_client.file_create_folder("files")
|
dropbox_client.file_create_folder("files")
|
||||||
|
30
erpnext/setup/doctype/backup_manager/backup_files_list.html
Normal file
30
erpnext/setup/doctype/backup_manager/backup_files_list.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<table class="table table-bordered" style="max-width: 600px;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width: 30%;">
|
||||||
|
{{ __("Date") }}
|
||||||
|
</th>
|
||||||
|
<th style="width: 50%;">
|
||||||
|
{{ __("File") }}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{{ __("Size") }}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for (var i=0; i < files.length; i++) { %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
{{ files[i][1] }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ files[i][0] }}" target="_blank">{{ files[i][0] }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ files[i][2] }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% } %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@ -2,35 +2,16 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
$.extend(cur_frm.cscript, {
|
$.extend(cur_frm.cscript, {
|
||||||
|
onload_post_render: function() {
|
||||||
|
cur_frm.fields_dict.allow_dropbox_access.$input.addClass("btn-primary");
|
||||||
|
|
||||||
|
if(cur_frm.doc.__onload && cur_frm.doc.__onload.files) {
|
||||||
|
$(frappe.render_template("backup_files_list", {files:cur_frm.doc.__onload.files}))
|
||||||
|
.appendTo(cur_frm.fields_dict.current_backups.$wrapper.empty());
|
||||||
|
}
|
||||||
|
},
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
cur_frm.disable_save();
|
cur_frm.disable_save();
|
||||||
|
|
||||||
if(!(cint(cur_frm.doc.dropbox_access_allowed) ||
|
|
||||||
cint(cur_frm.doc.gdrive_access_allowed))) {
|
|
||||||
cur_frm.set_intro(__("You can start by selecting backup frequency and granting access for sync"));
|
|
||||||
} else {
|
|
||||||
var services = {
|
|
||||||
"dropbox": __("Dropbox")
|
|
||||||
// "gdrive": __("Google Drive")
|
|
||||||
}
|
|
||||||
var active_services = [];
|
|
||||||
|
|
||||||
$.each(services, function(service, label) {
|
|
||||||
var access_allowed = cint(cur_frm.doc[service + "_access_allowed"]);
|
|
||||||
var frequency = cur_frm.doc["upload_backups_to_" + service];
|
|
||||||
if(access_allowed && frequency && frequency !== "Never") {
|
|
||||||
active_services.push(label + " [" + frequency + "]");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(active_services.length > 0) {
|
|
||||||
cur_frm.set_intro(__("Backups will be uploaded to") + ": " +
|
|
||||||
frappe.utils.comma_and(active_services));
|
|
||||||
} else {
|
|
||||||
cur_frm.set_intro("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
validate_send_notifications_to: function() {
|
validate_send_notifications_to: function() {
|
||||||
|
@ -8,16 +8,22 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "setup",
|
"fieldname": "setup",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Setup",
|
"label": "Download Backups",
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Email ids separated by commas.",
|
"fieldname": "current_backups",
|
||||||
"fieldname": "send_notifications_to",
|
"fieldtype": "HTML",
|
||||||
"fieldtype": "Data",
|
"label": "Current Backups",
|
||||||
"label": "Send Notifications To",
|
|
||||||
"permlevel": 0,
|
"permlevel": 0,
|
||||||
"reqd": 1
|
"precision": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "",
|
||||||
|
"fieldname": "sync_with_dropbox",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Sync with Dropbox",
|
||||||
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "backup_right_now",
|
"fieldname": "backup_right_now",
|
||||||
@ -28,19 +34,30 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Note: Backups and files are not deleted from Dropbox, you will have to delete them manually.",
|
"fieldname": "send_backups_to_dropbox",
|
||||||
"fieldname": "sync_with_dropbox",
|
"fieldtype": "Check",
|
||||||
"fieldtype": "Section Break",
|
"label": "Send Backups to Dropbox",
|
||||||
"label": "Sync with Dropbox",
|
"permlevel": 0,
|
||||||
"permlevel": 0
|
"precision": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "send_backups_to_dropbox",
|
||||||
|
"description": "Note: Backups and files are not deleted from Dropbox, you will have to delete them manually.",
|
||||||
"fieldname": "upload_backups_to_dropbox",
|
"fieldname": "upload_backups_to_dropbox",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Upload Backups to Dropbox",
|
"label": "Upload Backups to Dropbox",
|
||||||
"options": "Never\nWeekly\nDaily",
|
"options": "Never\nWeekly\nDaily",
|
||||||
"permlevel": 0
|
"permlevel": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "send_backups_to_dropbox",
|
||||||
|
"description": "Email ids separated by commas.",
|
||||||
|
"fieldname": "send_notifications_to",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Send Notifications To",
|
||||||
|
"permlevel": 0,
|
||||||
|
"reqd": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "dropbox_access_key",
|
"fieldname": "dropbox_access_key",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
@ -66,6 +83,7 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "send_backups_to_dropbox",
|
||||||
"fieldname": "allow_dropbox_access",
|
"fieldname": "allow_dropbox_access",
|
||||||
"fieldtype": "Button",
|
"fieldtype": "Button",
|
||||||
"label": "Allow Dropbox Access",
|
"label": "Allow Dropbox Access",
|
||||||
@ -140,7 +158,7 @@
|
|||||||
"icon": "icon-cloud-upload",
|
"icon": "icon-cloud-upload",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"modified": "2015-02-05 05:11:34.700674",
|
"modified": "2015-05-26 04:54:10.193573",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Backup Manager",
|
"name": "Backup Manager",
|
||||||
|
@ -4,13 +4,36 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from frappe.utils import get_site_path
|
||||||
|
from frappe.utils.data import convert_utc_to_user_timezone
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
|
||||||
class BackupManager(Document):
|
class BackupManager(Document):
|
||||||
pass
|
def onload(self):
|
||||||
|
self.set_onload("files", get_files())
|
||||||
|
|
||||||
|
def get_files():
|
||||||
|
def get_time(path):
|
||||||
|
dt = os.path.getmtime(path)
|
||||||
|
return convert_utc_to_user_timezone(datetime.datetime.utcfromtimestamp(dt)).strftime('%Y-%m-%d %H:%M')
|
||||||
|
|
||||||
|
def get_size(path):
|
||||||
|
size = os.path.getsize(path)
|
||||||
|
if size > 1048576:
|
||||||
|
return "{0:.1f}M".format(float(size) / 1048576)
|
||||||
|
else:
|
||||||
|
return "{0:.1f}K".format(float(size) / 1024)
|
||||||
|
|
||||||
|
path = get_site_path('private', 'backups')
|
||||||
|
files = [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))]
|
||||||
|
files = [('/backups/' + _file,
|
||||||
|
get_time(os.path.join(path, _file)),
|
||||||
|
get_size(os.path.join(path, _file))) for _file in files]
|
||||||
|
return files
|
||||||
|
|
||||||
def take_backups_daily():
|
def take_backups_daily():
|
||||||
take_backups_if("Daily")
|
take_backups_if("Daily")
|
||||||
@ -19,11 +42,12 @@ def take_backups_weekly():
|
|||||||
take_backups_if("Weekly")
|
take_backups_if("Weekly")
|
||||||
|
|
||||||
def take_backups_if(freq):
|
def take_backups_if(freq):
|
||||||
if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
|
if frappe.db.get_value("Backup Manager", None, "send_backups_to_dropbox"):
|
||||||
take_backups_dropbox()
|
if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
|
||||||
|
take_backups_dropbox()
|
||||||
|
|
||||||
# if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
|
# if frappe.db.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
|
||||||
# take_backups_gdrive()
|
# take_backups_gdrive()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def take_backups_dropbox():
|
def take_backups_dropbox():
|
||||||
|
Loading…
Reference in New Issue
Block a user