diff options
author | Rosy Song <rosysong@rosinson.com> | 2018-09-08 15:07:01 +0800 |
---|---|---|
committer | Rosy Song <rosysong@rosinson.com> | 2018-09-08 15:07:01 +0800 |
commit | 9840d310e2e3a54a3d53fc206f2d406402b42128 (patch) | |
tree | ae8b47a33c239034093c300f41a24492247b8418 /modules/luci-mod-admin-full/luasrc/controller/admin | |
parent | 18b4483fe76885061ea8d57e01a2fafc25de7790 (diff) |
modules: add backup module for mtdblock devices
Signed-off-by: Rosy Song <rosysong@rosinson.com>
Diffstat (limited to 'modules/luci-mod-admin-full/luasrc/controller/admin')
-rw-r--r-- | modules/luci-mod-admin-full/luasrc/controller/admin/system.lua | 18 |
1 files changed, 18 insertions, 0 deletions
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 2fa7847fc6..46d2e36c32 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" |