mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add multiple backup on server support
This commit is contained in:
parent
da1744ae8a
commit
4a1ac7bbbb
3 changed files with 65 additions and 9 deletions
|
@ -1321,7 +1321,18 @@ end
|
||||||
function backupgr()
|
function backupgr()
|
||||||
local get_backup = luci.http.formvalue("restore") or ""
|
local get_backup = luci.http.formvalue("restore") or ""
|
||||||
if get_backup ~= "" then
|
if get_backup ~= "" then
|
||||||
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_get >/dev/null 2>/dev/null")
|
local dobackup = 0
|
||||||
|
ucic:foreach("openmptcprouter","server", function(s)
|
||||||
|
servername = s[".name"]
|
||||||
|
local get_selected_backup = luci.http.formvalue(servername .. "") or ""
|
||||||
|
if get_selected_backup ~= "" then
|
||||||
|
dobackup = 1
|
||||||
|
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_get " .. servername .. " " .. get_selected_backup .. ">/dev/null 2>/dev/null")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
if dobackup == 0 then
|
||||||
|
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_get >/dev/null 2>/dev/null")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local send_backup = luci.http.formvalue("save") or ""
|
local send_backup = luci.http.formvalue("save") or ""
|
||||||
if send_backup ~= "" then
|
if send_backup ~= "" then
|
||||||
|
|
|
@ -16,10 +16,36 @@ menuentry = ucic:get("openmptcprouter","settings","menu") or "openmptcprouter"
|
||||||
%>
|
%>
|
||||||
<h3><%=servername%></h3>
|
<h3><%=servername%></h3>
|
||||||
<%
|
<%
|
||||||
if luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup") ~= nil then
|
if luci.model.uci.cursor():get("openmptcprouter",servername,"allbackup") ~= nil then
|
||||||
%>
|
%>
|
||||||
<div class="cbi-section-node">
|
<div class="cbi-section-node">
|
||||||
<%:Last available backup on server:%> <%=os.date('%d-%b-%Y', luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup"))%>
|
<div class="cbi-value">
|
||||||
|
<label class="cbi-value-title"><%:Backup availables on server%></label>
|
||||||
|
<div class="cbi-value-field">
|
||||||
|
<select class="cbi-input-select" name="<%=servername%>-backup" size="1">
|
||||||
|
<option value=""></option>
|
||||||
|
<%
|
||||||
|
lastmodif=""
|
||||||
|
allbackup=luci.model.uci.cursor():get("openmptcprouter",servername,"allbackup")
|
||||||
|
for _, backup in pairs(allbackup) do
|
||||||
|
filemodif=split(backup, '|')
|
||||||
|
if filemodif[2] ~= lastmodif then
|
||||||
|
lastmodif=filemodif[2]
|
||||||
|
%>
|
||||||
|
<option value="<%=filemodif[1]%>"><%=os.date('%c',filemodif[2])%></option>
|
||||||
|
<%
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<%
|
||||||
|
elseif luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup") ~= nil then
|
||||||
|
%>
|
||||||
|
<div class="cbi-section-node">
|
||||||
|
<%:Last available backup on server:%> <%=os.date('%c', luci.model.uci.cursor():get("openmptcprouter",servername,"lastbackup"))%>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="cbi-section-node">
|
<div class="cbi-section-node">
|
||||||
|
@ -29,6 +55,7 @@ menuentry = ucic:get("openmptcprouter","settings","menu") or "openmptcprouter"
|
||||||
<%
|
<%
|
||||||
end)
|
end)
|
||||||
%>
|
%>
|
||||||
|
<br/>
|
||||||
<input type="submit" class="cbi-button cbi-button-action important" name="restore" value="<%:Restore backup%>"/>
|
<input type="submit" class="cbi-button cbi-button-action important" name="restore" value="<%:Restore backup%>"/>
|
||||||
<input type="submit" class="cbi-button cbi-button-action important" name="save" value="<%:Send backup%>"/>
|
<input type="submit" class="cbi-button cbi-button-action important" name="save" value="<%:Send backup%>"/>
|
||||||
|
|
||||||
|
|
|
@ -1770,6 +1770,7 @@ _backup_get() {
|
||||||
|
|
||||||
_backup_get_and_apply() {
|
_backup_get_and_apply() {
|
||||||
servername=$1
|
servername=$1
|
||||||
|
backupfile=$2
|
||||||
token=""
|
token=""
|
||||||
vps_config=""
|
vps_config=""
|
||||||
_login
|
_login
|
||||||
|
@ -1780,7 +1781,12 @@ _backup_get_and_apply() {
|
||||||
EOF
|
EOF
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vps_backup=$(_get_json "backupget")
|
if [ -n "$backupfile" ]; then
|
||||||
|
echo "get $backupfile"
|
||||||
|
vps_backup=$(_get_json "backupget?filename=${backupfile}")
|
||||||
|
else
|
||||||
|
vps_backup=$(_get_json "backupget")
|
||||||
|
fi
|
||||||
[ -z "$vps_backup" ] && return
|
[ -z "$vps_backup" ] && return
|
||||||
backup_data="$(echo "$vps_backup" | jsonfilter -q -e '@.data')"
|
backup_data="$(echo "$vps_backup" | jsonfilter -q -e '@.data')"
|
||||||
backup_sha256sum="$(echo "$vps_backup" | jsonfilter -q -e '@.sha256sum')"
|
backup_sha256sum="$(echo "$vps_backup" | jsonfilter -q -e '@.sha256sum')"
|
||||||
|
@ -1791,11 +1797,16 @@ _backup_get_and_apply() {
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_get() {
|
backup_get() {
|
||||||
lastbackup=""
|
backuptoapply=$2
|
||||||
serverbackup=""
|
if [ -n "$backuptoapply" ]; then
|
||||||
config_load openmptcprouter
|
_backup_get_and_apply $1 $2
|
||||||
config_foreach _backup_get server
|
else
|
||||||
[ -n "$serverbackup" ] && _backup_get_and_apply $serverbackup
|
lastbackup=""
|
||||||
|
serverbackup=""
|
||||||
|
config_load openmptcprouter
|
||||||
|
config_foreach _backup_get server
|
||||||
|
[ -n "$serverbackup" ] && _backup_get_and_apply $serverbackup
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_backup_list() {
|
_backup_list() {
|
||||||
|
@ -1819,6 +1830,13 @@ _backup_list() {
|
||||||
backup_lastmodif="$(echo "$vps_backup" | jsonfilter -q -e '@.modif')"
|
backup_lastmodif="$(echo "$vps_backup" | jsonfilter -q -e '@.modif')"
|
||||||
[ -n "$backup_lastmodif" ] && {
|
[ -n "$backup_lastmodif" ] && {
|
||||||
uci -q set openmptcprouter.$servername.lastbackup=$backup_lastmodif
|
uci -q set openmptcprouter.$servername.lastbackup=$backup_lastmodif
|
||||||
|
backup_all="$(echo "$vps_backup" | jsonfilter -q -e '@.sorted[*]')"
|
||||||
|
uci -q del openmptcprouter.$servername.allbackup
|
||||||
|
echo "$vps_backup" | jsonfilter -q -e '@.sorted[*]' | while read backup; do
|
||||||
|
name=$(echo "$backup" | jsonfilter -q -e '@[0]' | tr -d '\n')
|
||||||
|
modiftime=$(echo "$backup" | jsonfilter -q -e '@[1]' | tr -d '\n')
|
||||||
|
uci -q add_list openmptcprouter.$servername.allbackup="${name}|${modiftime}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue