From: Rosy Song Date: Sat, 8 Sep 2018 07:07:01 +0000 (+0800) Subject: modules: add backup module for mtdblock devices X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=refs%2Fpull%2F2122%2Fhead;p=oweals%2Fluci.git modules: add backup module for mtdblock devices Signed-off-by: Rosy Song --- diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua index 823e20770..1436a3a23 100644 --- a/modules/luci-base/luasrc/sys.lua +++ b/modules/luci-base/luasrc/sys.lua @@ -70,6 +70,24 @@ function mounts() return data end +function mtds() + local data = {} + + if fs.access("/proc/mtd") then + for l in io.lines("/proc/mtd") do + local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') + if s and n then + local d = {} + d.size = tonumber(s, 16) + d.name = n + table.insert(data, d) + end + end + end + + return data +end + -- containing the whole environment is returned otherwise this function returns -- the corresponding string value for the given name or nil if no such variable -- exists. diff --git a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua index 2fa7847fc..46d2e36c3 100644 --- a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua +++ b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua @@ -35,6 +35,7 @@ function index() entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70) entry({"admin", "system", "flashops", "reset"}, post("action_reset")) entry({"admin", "system", "flashops", "backup"}, post("action_backup")) + entry({"admin", "system", "flashops", "backupmtdblock"}, post("action_backupmtdblock")) entry({"admin", "system", "flashops", "backupfiles"}, form("admin_system/backupfiles")) -- call() instead of post() due to upload handling! @@ -318,6 +319,23 @@ function action_backup() luci.ltn12.pump.all(reader, luci.http.write) end +function action_backupmtdblock() + local http = require "luci.http" + local mv = http.formvalue("mtdblockname") + local m, s, n = mv:match('^([^%s]+)/([^%s]+)/([^%s]+)') + + local reader = ltn12_popen("dd if=/dev/mtd%s conv=fsync,notrunc 2>/dev/null" % n) + + luci.http.header( + 'Content-Disposition', 'attachment; filename="backup-%s-%s-%s.bin"' %{ + luci.sys.hostname(), m, + os.date("%Y-%m-%d") + }) + + luci.http.prepare_content("application/octet-stream") + luci.ltn12.pump.all(reader, luci.http.write) +end + function action_restore() local fs = require "nixio.fs" local http = require "luci.http" diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm b/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm index f3d2e8d7b..8204d38e3 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm @@ -59,6 +59,40 @@
<%:The backup archive does not appear to be a valid gzip file.%>
<% end %> + + <% local mtds = require("luci.sys").mtds(); if #mtds > 0 then -%> +

<%:Save mtdblock contents%>

+
<%:Click "Save mtdblock" to download specified mtdblock file. (NOTE: THIS FEATURE IS FOR PROFESSIONALS! )%>
+
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+
+ <% end %> +