生成备份文件时所使用的脚本中调用的命令为sysgrade
local image_tmp = "/tmp/firmware.img"
local backup_cmd = "sysupgrade --create-backup - 2>/dev/null"
local fsysup = "openwrt-ar71xx-generic-ap143-16M-squashfs-sysupgrade.bin"
local fwname = "firmware.tar.gz"
local image_tmp_gz = "/tmp/"..fwname最后将文件压缩为 backup-hostname-date.tar.gz (eg: backup-openwrt-2016-01-09.tar.gz)
luci.sys.exec("cd /tmp; tar -zxvf "..fwname.."; mv "..fsysup.." "..image_tmp.."; rm "..image_tmp_gz)
其中压缩文件.tar.gz中包含的内容有: lib/upgrade/keep.d/ 目录下文件中所有的内容以及 etc/sysupgrade.conf中包含的内容
主要有:
# cd lib/upgrade/keep.d/
# lsbase-files uboot-envtoolsbase-files-essential uhttpd# cat base-files/etc/config/ --config目录下所有文件/etc/dropbear/ --dropbear目录下所有文件/etc/crontabs/ --crontabs目录下所有文件# cat base-files-essential # Essential files that will be always kept/etc/hosts --etc目录下的这些文件/etc/inittab/etc/group/etc/passwd/etc/profile/etc/shadow/etc/shells/etc/sysctl.conf/etc/rc.local# cat uboot-envtools /etc/config/ubootenv --uboot相关文件/etc/fw_env.config# cat uhttpd /etc/uhttpd.crt --uhttpd相关文件/etc/uhttpd.key如果还想备份其他文件,可以在/etc目录下的sysupgrade.conf中添加相应目录或文件。
将备份的压缩文件解压后可以看到
tar zxvf backup-openwrt-2016-01-19.tar.gz
etc/config/accountetc/config/checkrssietc/config/dropbearetc/config/firewalletc/config/link.logetc/config/lldpdetc/config/lucietc/config/mcsetc/config/networketc/config/snmpdetc/config/snmpdataetc/config/systemetc/config/ubootenvetc/config/ucitracketc/config/uhttpdetc/config/wirelessetc/config/wonoffetc/crontabs/cron.updateetc/crontabs/rootetc/dropbear/dropbear_dss_host_keyetc/dropbear/dropbear_rsa_host_keyetc/fw_env.configetc/groupetc/hostsetc/inittabetc/passwdetc/profileetc/rc.localetc/shadowetc/shellsetc/sysctl.confetc/sysupgrade.confetc/uhttpd.crtetc/uhttpd.key
如果在sysupgrade.conf中添加 /overlay目录则:
# cat sysupgrade.conf
## This file contains files and directories that should## be preserved during an upgrade.# /etc/example.conf
# /etc/openvpn//overlay --将overlay目录下的文件压缩到备份中
解压备份文件可得
tar zxvf backup-openwrt-2016-01-19.tar.gz
etc/config/accountetc/config/checkrssietc/config/dropbearetc/config/firewalletc/config/link.logetc/config/lldpdetc/config/lucietc/config/mcsetc/config/networketc/config/snmpdetc/config/snmpdataetc/config/systemetc/config/ubootenvetc/config/ucitracketc/config/uhttpdetc/config/wirelessetc/config/wonoffetc/crontabs/cron.updateetc/crontabs/rootetc/dropbear/dropbear_dss_host_keyetc/dropbear/dropbear_rsa_host_keyetc/fw_env.configetc/groupetc/hostsetc/inittabetc/passwdetc/profileetc/rc.localetc/shadowetc/shellsetc/sysctl.confetc/sysupgrade.confetc/uhttpd.crtetc/uhttpd.keyoverlay/etc/config/accountoverlay/etc/config/checkrssioverlay/etc/config/dropbearoverlay/etc/config/firewalloverlay/etc/config/link.logoverlay/etc/config/lldpdoverlay/etc/config/lucioverlay/etc/config/mcsoverlay/etc/config/networkoverlay/etc/config/snmpdoverlay/etc/config/snmpdataoverlay/etc/config/systemoverlay/etc/config/ubootenvoverlay/etc/config/ucitrackoverlay/etc/config/uhttpdoverlay/etc/config/wirelessoverlay/etc/config/wonoffoverlay/etc/crontabs/cron.updateoverlay/etc/crontabs/rootoverlay/etc/dropbear/dropbear_dss_host_keyoverlay/etc/dropbear/dropbear_rsa_host_keyoverlay/etc/fw_env.configoverlay/etc/groupoverlay/etc/hostsoverlay/etc/inittaboverlay/etc/passwdoverlay/etc/profileoverlay/etc/rc.localoverlay/etc/shadowoverlay/etc/shellsoverlay/etc/sysctl.confoverlay/etc/sysupgrade.confoverlay/etc/uhttpd.crtoverlay/etc/uhttpd.keyoverlay/root/logsoverlay/usr/lib/snmp/snmpd.confetc/uhttpd.keyetc/uhttpd.crt