summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2009-11-02 15:59:46 +0000
committerSteven Barth <steven@midlink.org>2009-11-02 15:59:46 +0000
commita5a9625a457cd377418810cd86276d4597cc589a (patch)
treef530c55cb1544fadc6000846872d4cd68edd3ddb /modules
parent86e00cb771b81dce8d9629326a5c25b92a024d04 (diff)
NIU: Backup system settings
Diffstat (limited to 'modules')
-rw-r--r--modules/niu/luasrc/controller/niu/system.lua46
1 files changed, 45 insertions, 1 deletions
diff --git a/modules/niu/luasrc/controller/niu/system.lua b/modules/niu/luasrc/controller/niu/system.lua
index bb78edf08..45f7cb615 100644
--- a/modules/niu/luasrc/controller/niu/system.lua
+++ b/modules/niu/luasrc/controller/niu/system.lua
@@ -12,7 +12,7 @@ You may obtain a copy of the License at
$Id$
]]--
-local req = require
+local require, pairs, unpack = require, pairs, unpack
module "luci.controller.niu.system"
function index()
@@ -20,4 +20,48 @@ function index()
entry({"niu", "system", "general"},
cbi("niu/system/general", {on_success_to={"niu"}}), "General", 10)
+
+ entry({"niu", "system", "backup"}, call("backup"), "Backup Settings", 20)
end
+
+function backup()
+ local os = require "os"
+ local uci = require "luci.model.uci".cursor()
+ local nixio, nutl = require "nixio", require "nixio.util"
+ local fs = require "nixio.fs"
+ local http = require "luci.http"
+
+
+ local call = {"/bin/tar", "-cz"}
+ for k, v in pairs(uci:get_all("luci", "flash_keep")) do
+ if k:byte() ~= 46 then -- k[1] ~= "."
+ nutl.consume(fs.glob(v), call)
+ end
+ end
+
+
+ http.header(
+ 'Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' % {
+ nixio.uname().nodename, os.date("%Y-%m-%d")
+ }
+ )
+ http.prepare_content("application/x-targz")
+
+
+ local fdin, fdout = nixio.pipe()
+ local devnull = nixio.open("/dev/null", "r+")
+ local proc = nixio.fork()
+
+ if proc == 0 then
+ fdin:close()
+ nixio.dup(devnull, nixio.stdin)
+ nixio.dup(devnull, nixio.stderr)
+ nixio.dup(fdout, nixio.stdout)
+ nixio.exec(unpack(call))
+ os.exit(1)
+ end
+
+ fdout:close()
+ http.splice(fdin)
+ http.close()
+end \ No newline at end of file