Backup quotas before save changes

Report issues relating to bandwith monitoring, bandwidth quotas or QoS in this forum.

Moderator: Moderators

Post Reply
Tareq
Posts: 58
Joined: Mon Dec 14, 2015 6:56 am

Backup quotas before save changes

Post by Tareq »

hi there

When router hard power off while saving , all quotas removed.

I need to make Backup for "/usr/data/quotas" directory to other directory before saving Quotas changes.

I added this line but it not worked for me, please any one can help me to make this right.

cp /usr/data/quotas /usr/data/quotas_backup_m


Code: Select all

function saveChanges(){
   cp /usr/data/quotas /usr/data/quotas_backup_m

   setControlsEnabled(!1,!0);var e=[],t=uciOriginal.getAllSectionsOfType(pkg,"quota");while(t.length>0){var n=t.shift();uciOriginal.removeSection(pkg,n),e.push("uci del "+pkg+"."+n)}e.push("uci commit");var r=uci.getAllSectionsOfType(pkg,"quota"),i="\nuci del gargoyle.status.quotause ; uci commit ;\n",s=[];while(r.length>0){var n=r.shift(),o=uci.get(pkg,n,"id");s[o]=n,changedIds[o]==1&&uci.set(pkg,n,"ignore_backup_at_next_restore","1")}var u=document.getElementById("quota_table_container").firstChild,a=getTableDataArray(u,!0,!1),f=0;for(f=0;f<a.length;f++){var l=a[f][rowCheckIndex],c=s[l.id];c!=null&&(uci.set(pkg,c,"enabled",l.checked?"1":"0"),l.checked&&(i='\nuci set gargoyle.status.quotause="225" ; uci commit ;\n'))}var h=[];h.push("sh /usr/lib/gargoyle/restart_firewall.sh"),h.push('if [ -d "/usr/data/quotas/" ] ; then rm -rf /usr/data/quotas/* ; fi ;'),h.push("backup_quotas");var p=e.join("\n")+"\n"+uci.getScriptCommands(uciOriginal)+"\n"+i+"\n"+h.join("\n"),d=getParameterDefinition("commands",p)+"&"+getParameterDefinition("hash",document.cookie.replace(/^.*hash=/,"").replace(/[\t ;]+.*$/,"")),v=function(e){e.readyState==4&&(setControlsEnabled(!0),window.location.href=window.location.href)};runAjax("POST","utility/run_commands.sh",d,v)
      }
TP-LINK WR841N. V8.4 | Gargoyle 1.9 | South Yemen

Lantis
Moderator
Posts: 5624
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Backup quotas before save changes

Post by Lantis »

JavaScript doesn’t understand that command. You need to run it against the router, not a browser.
Notice how in the following lines all router commands are pushed to an array, then executed by another process?

Try using the full files instead of minified when making changes. Everything is a lot easier to understand.
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

Tareq
Posts: 58
Joined: Mon Dec 14, 2015 6:56 am

Re: Backup quotas before save changes

Post by Tareq »

I put this line in quotas.sh script , and the files coped done when I open quotas web page.
but i need to run thes line when click save button.

I tried to make my code in function then call function from onclick="myfunction", but not working.

Code: Select all

   cp /usr/data/quotas/* /usr/data/quotas_backup_m/
TP-LINK WR841N. V8.4 | Gargoyle 1.9 | South Yemen

Lantis
Moderator
Posts: 5624
Joined: Mon Jan 05, 2015 5:33 am
Location: Australia

Re: Backup quotas before save changes

Post by Lantis »

i Don’t think you understood my reply.
JavaScript runs in the user’s browser.
Shell runs on the router.

If we want to use JavaScript to run a shell command, we need to send it to the router to be executed. You can’t just write it in the JavaScript.

Understand these lines and it will all become clear.
https://github.com/ericpaulbishop/gargo ... js#L70-L87
http://lantisproject.com/downloads/gargoyle_ispyisail.php for the latest releases
Please be respectful when posting. I do this in my free time on a volunteer basis.

Post Reply