Page 1 of 1

Backup quotas before save changes

Posted: Fri Apr 19, 2019 3:56 pm
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)
		}

Re: Backup quotas before save changes

Posted: Fri Apr 19, 2019 5:43 pm
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.

Re: Backup quotas before save changes

Posted: Fri Apr 19, 2019 6:54 pm
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/

Re: Backup quotas before save changes

Posted: Fri Apr 19, 2019 7:32 pm
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