modules: add backup module for mtdblock devices
Signed-off-by: Rosy Song <rosysong@rosinson.com>
This commit is contained in:
parent
18b4483fe7
commit
9840d310e2
3 changed files with 70 additions and 0 deletions
|
@ -70,6 +70,24 @@ function mounts()
|
||||||
return data
|
return data
|
||||||
end
|
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
|
-- containing the whole environment is returned otherwise this function returns
|
||||||
-- the corresponding string value for the given name or nil if no such variable
|
-- the corresponding string value for the given name or nil if no such variable
|
||||||
-- exists.
|
-- exists.
|
||||||
|
|
|
@ -35,6 +35,7 @@ function index()
|
||||||
entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70)
|
entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70)
|
||||||
entry({"admin", "system", "flashops", "reset"}, post("action_reset"))
|
entry({"admin", "system", "flashops", "reset"}, post("action_reset"))
|
||||||
entry({"admin", "system", "flashops", "backup"}, post("action_backup"))
|
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"))
|
entry({"admin", "system", "flashops", "backupfiles"}, form("admin_system/backupfiles"))
|
||||||
|
|
||||||
-- call() instead of post() due to upload handling!
|
-- call() instead of post() due to upload handling!
|
||||||
|
@ -318,6 +319,23 @@ function action_backup()
|
||||||
luci.ltn12.pump.all(reader, luci.http.write)
|
luci.ltn12.pump.all(reader, luci.http.write)
|
||||||
end
|
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()
|
function action_restore()
|
||||||
local fs = require "nixio.fs"
|
local fs = require "nixio.fs"
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
|
|
|
@ -59,6 +59,40 @@
|
||||||
<div class="cbi-section-error"><%:The backup archive does not appear to be a valid gzip file.%></div>
|
<div class="cbi-section-error"><%:The backup archive does not appear to be a valid gzip file.%></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% local mtds = require("luci.sys").mtds(); if #mtds > 0 then -%>
|
||||||
|
<h3><%:Save mtdblock contents%></h3>
|
||||||
|
<div class="cbi-section-descr"><%:Click "Save mtdblock" to download specified mtdblock file. (NOTE: THIS FEATURE IS FOR PROFESSIONALS! )%></div>
|
||||||
|
<div class="cbi-section-node">
|
||||||
|
<form class="inline" method="post" action="<%=url('admin/system/flashops/backupmtdblock')%>">
|
||||||
|
<input type="hidden" name="token" value="<%=token%>" />
|
||||||
|
<div class="cbi-value">
|
||||||
|
<label class="cbi-value-title" for="mtdblockname"><%:Choose mtdblock%></label>
|
||||||
|
<div class="cbi-value-field">
|
||||||
|
<select class="cbi-input-select" data-update="change" name="mtdblockname" id="mtdblockname">
|
||||||
|
<% for i, key in ipairs(mtds) do
|
||||||
|
if key and key.name ~= "rootfs_data" then -%>
|
||||||
|
<option<%=
|
||||||
|
attr("id", "mtdblockname-" .. key.name) ..
|
||||||
|
attr("value", key.name .. '/'.. key.size .. '/' .. i - 1) ..
|
||||||
|
attr("data-index", i) ..
|
||||||
|
ifattr(key.name == "linux" or key.name == "firmware", "selected", "selected")
|
||||||
|
%>><%=pcdata(key.name)%></option>
|
||||||
|
<% end
|
||||||
|
end -%>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="cbi-value cbi-value-last<% if reset_avail then %> cbi-value-error<% end %>">
|
||||||
|
<label class="cbi-value-title" for="image"><%:Download mtdblock%></label>
|
||||||
|
<div class="cbi-value-field">
|
||||||
|
<input type="submit" class="cbi-button cbi-button-action important" value="<%:Save mtdblock%>" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="cbi-section">
|
<div class="cbi-section">
|
||||||
|
|
Loading…
Reference in a new issue