1
0
Fork 0
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:
Ycarus (Yannick Chabanois) 2023-09-01 09:23:28 +02:00
parent da1744ae8a
commit 4a1ac7bbbb
3 changed files with 65 additions and 9 deletions

View file

@ -1321,8 +1321,19 @@ 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
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") 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
luci.sys.call("/etc/init.d/openmptcprouter-vps backup_send >/dev/null 2>/dev/null") luci.sys.call("/etc/init.d/openmptcprouter-vps backup_send >/dev/null 2>/dev/null")

View file

@ -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%>"/>

View file

@ -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
} }
if [ -n "$backupfile" ]; then
echo "get $backupfile"
vps_backup=$(_get_json "backupget?filename=${backupfile}")
else
vps_backup=$(_get_json "backupget") 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() {
backuptoapply=$2
if [ -n "$backuptoapply" ]; then
_backup_get_and_apply $1 $2
else
lastbackup="" lastbackup=""
serverbackup="" serverbackup=""
config_load openmptcprouter config_load openmptcprouter
config_foreach _backup_get server config_foreach _backup_get server
[ -n "$serverbackup" ] && _backup_get_and_apply $serverbackup [ -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
} }
} }