Backup Config Module - Beta - Final stage

It seems pretty tricky to me. :pensive:

Good news :smile:

I’ve worked on the backup Config module and until now the following are possible:

  • each archive has date in filename
  • can create more than 1 backup file
  • Backup script executes only if there is no backup or if the last backup done is different than the configuration (same as original but with multiple bkp files)
  • the backup can be triggered from the webinterface button (same as original but with multiple bkp files)
  • added table of current backups to the webgui (see screenshot)

To add ajax functionality to the Download / Delete / Restore buttons.

Curently I’m having some issues with the path reference to the ajax library.
It is not getting the path to the “bkp_jlib_ajax.php” file that i have placed in the “usr/share/nethesis/NethServer/Template/BackupConfig”

Instead it is still asking to get the file from: /en-US/BackupConfig/Backup/bkp_jlib_ajax.php
the getModuleUrl() returns : /en-US/BackupConfig/Backup, But this is not usable for the script.

Maybe some of the devs can land a hand ? :smile: @davidep @giacomo

Best regards


Really great job !

What UI behaviour are you trying to achieve? What should happen if the user press those buttons?

Also I remark the action buttons shown by the screenshot are different from any other table in server-manager: we should use the same appearance here!

Nethgui has a set of reusable components to build a such table. I recall the VPN > Accounts page:

What is expected to do the AJAX call? Why do you need bkp_jlib_ajax.php ?

Keep in mind that within the Server Manger, the entry point of each HTTP request must be index.php!

Could you try to adapt the Accounts.php case to this?

Hi Davide,

The ajax functionality is needed so when you click on the button, the action (delete or download or restore) is executed without re-loading the page.
The ajax library contains php functions that are executed on demand via javascript for those actions and nothing more.

The code you are using in NS is very object oriented, I have created the scripts procedural. It is too complex, and for me to try and understand how the framework works is impossible since it is not documented. I’ve tried to make some sense on the code but it is to spread between so many files.

I’ve resolved the reference call for the ajax lib by puting the file in the root of the netserver-manager.

I know that it is not the ideeal implementation but as I sayed, I have to learn the whole framework and funtctions of curent NS to make a module that is object oriented and more compatible.

Now the only issues that I’m facing is that I could not make the calls to system functions work for example to remove the specified backup file via exec(); and still to work on the restore call.


Having an effective and coherent UI style and behaviour is one of the framework goals and NethServer requirement …I know Nethgui is a Bad Guy and we lack documentation about it :alien:

However this is a kickstart:

Moreover, while developing you can see more debug messages from:


That controller must be enabled, by touch-ing an empty file:

touch /usr/share/nethesis/nethserver-manager/debug

PHP messages are logged to:

  • /var/log/httpd-admin/error_log
  • /var/log/messages

Could you start by sharing a PR for the backend part, so we can review it with @giacomo?

For the GUI I could steer you through the framework maze :wink:

Why we need removing the backup from the UI?

Can it be done by the backup-rotation logic?

It was just a feature but I did not implement a rotation function ( check that 10 files are allowed and delete the last if a backup is created)

It is planned but not yet developed.
And Having the posibility to delete on demand a file is always useful in my opinion.

I’ll try to see if you are available in the evening on IRC to discuss better :smile:


Can somebody explain and share snippets regarding the usage of the NS database?
I need to see the exact way in witch a value is stored in a key and then read / write / edited / deleted.

Best regards

open a CLI and give:

db [enter]

you’ll see the syntax and supported options

in any case

db configuration set mycustomconf configuration key1 value1 key2 value2

will create a new key in your configuration db

if then you give:

db configuration show mycustomconf

you’d see


the setprop and delprop flags can help you to add/modify a key/value or to remove it

db configuration setprop mycustomconf key1 newvalue key3 value3

will modify key1 and add key3

db configuration delprop mycustomconf key3

will delete key3

there are other commands, but I think you can discover yourself them :wink:


Thank you Stefano,
This is exactly what I wanted!
I’ll try to see if i can use this from perl scripts

Best regards

If you’re programming with Perl, you can invoke the esmith API directly. A lot of perl scripts under /etc/e-smith/events/actions/ use it!

Also available perl documentation from the CLI:

perldoc esmith::DB

…and so on!

I’m super interested in this and am following your progress @Ctek. Keep up the good work.


Can anyone offere some insight on why this does return always int (1) as error ?
it drives me nuts, I’ve tried exec() passtrouh() system() and the same result… And error 1 is generic miscellaneous error

function delete_backup($file_name) {
if (isset($file_name) and !empty($file_name) and (get_file_extension($file_name) == "xz")) 
  $command='/usr/bin/sudo "rm -f /var/lib/nethserver/backup/'.$file_name.'"';
  $result=exec($command, $out, $err);
  if ($result) {
		return ("Deleted backup ". $file_name);
		} else {
			return "Error removing: ". $file_name." Output: ".var_dump($out)." Error: ".var_dump($err);
} else {
 	return "Error, file is not valid for removal";

Did you catch the stderr?

Redirect stderr to stdout. Perhaps some Infos are there or have a look to Apache error log

Hi Davide,
In the log i get Permission Denied. … it seems that it is not possible to do anything on the files… not via php or via perl script.
I’ve tried also with sudo but the same result.

I think that www-data should be added to the group that has access on that folder or folders.

Please check sudo:

  • errors are also sent to auth syslog facility.
  • Sudo must be configured to allow executing that rm command.

“Please check sudo:” where to check ?

You are referring to add something like this to sudoers ?
user ALL=(ALL) NOPASSWD: /bin/rm /var/lib/nethserver/backup/*.xz

Ok so I’m thinking that it is better that I’ll use a perl script to remove the specified backup file (and resultant files md5).
Also this will be needed for the rotation of logs when i will implement one :smile:

So it will be better to add backup-config-remove to sudo allowed.

PS: why the restore-config did not work also? It was supposed to already be allowed in sudo, no ?



Hi guys I’ve got some good news :smile:

The RC1 release of the BackupConfig module is ready.
I’ve put the update in git and whoever want to test it can download the files and overwrite them.
With this update a new file has been added: delete-config that needs to be placed in /sbin/e-smith/

ATTENTION You will need to add the script /sbin/e-smith/delete-config to the sudoers, !!!

Here are some screens:
Normal page

Delete pushed:

Restore pushed:

Feedback on delete:

Please post here your feedback.

Best regards


Update: RC2 - 12/10/15

Hi guys,
Another update.

Please test and give feedback on this.

Note the /etc/e-smith/backup-config-rotate must be added to the sudoers!

Still to do:

  • add field in UI for user defined number of backups (current value is set to 15)
  • add routine/scripts to read/set/update the value of user defined Nr of backups to keep.

Best regards