summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-full/luasrc/controller
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-07-01 14:17:59 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-07-01 14:17:59 +0000
commit361cbfa9e139f68cdd079e2a87701fdc5ab944fd (patch)
treee240805c199cd73e816de33563710c528e29b0d4 /modules/admin-full/luasrc/controller
parent8cddaabf815b1fa87a40dc72ec23e865a77600af (diff)
modules/admin-full: fix backup generation (#74)
Diffstat (limited to 'modules/admin-full/luasrc/controller')
-rw-r--r--modules/admin-full/luasrc/controller/admin/system.lua41
1 files changed, 35 insertions, 6 deletions
diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua
index 56010ea9e..1aabe637a 100644
--- a/modules/admin-full/luasrc/controller/admin/system.lua
+++ b/modules/admin-full/luasrc/controller/admin/system.lua
@@ -130,9 +130,9 @@ end
function action_backup()
local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
- local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1"
- local backup_cmd = "tar -c %s | gzip 2>/dev/null"
-
+ local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
+ local backup_cmd = "tar -cz %s 2>/dev/null"
+
local restore_fpi
luci.http.setfilehandler(
function(meta, chunk, eof)
@@ -156,12 +156,11 @@ function action_backup()
luci.template.render("admin_system/applyreboot")
luci.sys.reboot()
elseif backup then
- luci.util.perror(backup_cmd:format(_keep_pattern()))
- local backup_fpi = io.popen(backup_cmd:format(_keep_pattern()), "r")
+ local reader = ltn12_popen(backup_cmd:format(_keep_pattern()))
luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' % {
luci.sys.hostname(), os.date("%Y-%m-%d")})
luci.http.prepare_content("application/x-targz")
- luci.ltn12.pump.all(luci.ltn12.source.file(backup_fpi), luci.http.write)
+ luci.ltn12.pump.all(reader, luci.http.write)
elseif reset then
luci.template.render("admin_system/applyreboot")
luci.util.exec("mtd -r erase rootfs_data")
@@ -341,3 +340,33 @@ function _keep_pattern()
end
return kpattern
end
+
+function ltn12_popen(command)
+
+ local fdi, fdo = nixio.pipe()
+ local pid = nixio.fork()
+
+ if pid > 0 then
+ fdo:close()
+ local close
+ return function()
+ local buffer = fdi:read(2048)
+ local wpid, stat = nixio.waitpid(pid, "nohang")
+ if not close and wpid and stat == "exited" then
+ close = true
+ end
+
+ if buffer and #buffer > 0 then
+ return buffer
+ elseif close then
+ fdi:close()
+ return nil
+ end
+ end
+ elseif pid == 0 then
+ nixio.dup(fdo, nixio.stdout)
+ fdi:close()
+ fdo:close()
+ nixio.exec("/bin/sh", "-c", command)
+ end
+end