Backup Config Module - Beta - Final stage

Hi. The following is a modification into NS files that wil make available the link to download the configuration backup.
Please note that this will require you make modifications into the NS files!!

The file that must be modified are:
/sbin/e-smith/backup-config
/usr/share/nethesis/NethServer/Template/BackupConfig/Backup.php
/usr/share/nethesis/NethServer/Module/BackupConfig/Backup.php

and you must create a php file in /usr/share/nethesis/nethserver-manager/

Let’s begin

File: /sbin/e-smith/backup-config

At the end of the file modify from this

$backup->send_notification();
exit 0;

to look like this

$backup->send_notification();
system("chmod 755 /var/lib/nethserver/backup/backup-config.tar.xz");
system("ln -s /var/lib/nethserver/backup/backup-config.tar.xz /usr/share/nethesis/nethserver-manager/bkp.tar.xz");
exit 0;

then modify the file:
File: /usr/share/nethesis/NethServer/Template/BackupConfig/Backup.php

modify the file above this line:

echo "<div id='bc_module_warning' class='ui-state-highlight'><span class='ui-icon ui-icon-info'></span>".$T('backup_config_label')."</div>";

to look like this:

if ((isset($view['size'])) && ($view['size']!= '-')) {echo '<a href="../download.php?d='.$view['file_time'].'" target="_blank" >Download</a></br>'. "</br>"; };
echo "<div id='bc_module_warning' class='ui-state-highlight'><span class='ui-icon ui-icon-info'></span>".$T('backup_config_label')."</div>";

and the last file to modify:
File: /usr/share/nethesis/NethServer/Module/BackupConfig/Backup.php

under this line:

$view['date'] = date("o-m-d G:i", $this->backup['date']);

add to look like this:

$view['date'] = date("o-m-d G:i", $this->backup['date']);
$view['file_time']= date("o-m-d_H-i", $this->backup['date']);

you must create one file in the folder:
/usr/share/nethesis/nethserver-manager/

Create a new php file “download.php”.
The file should contain:

<?php
$file_name = "bkp.tar.xz";
if(isset($_GET['d'])){$file_date=$_GET['d'];}else {$file_date=date("Y-m-d_H:i", filectime($file_name));};

if (file_exists($file_name)) {
        header('Cache-Control: public');
        header('Content-Type: application/zip');
        header('Content-Disposition: attachment; filename=' . $file_name.'_'.$file_date);
    
        readfile($file_name);
        ob_flush();
        die();
        } else {
                die('File not found!');
                };
?>

After modification when a backup file exists a Download link will apear.

I hope this helps :smile:

Best regards
Bogdan

6 Likes

Great proposal @Ctek!
I think it should require also the admin authentication to start the download, right?

Hi Davide,
I think this is not necessary because you are under admin account.
You cannot do that on user account where are very limited rights.

Maybe I’m wrong …

Gabriel

If the URL is well known (or easy to guess) everyone can download the configuration backup! :open_mouth:

Anyway, I think the basic idea is very good enhancement and we could work to improve it. What do you think?

2 Likes

As I already say in other post:

I love this Forum! I like you guys!
I think is the best Forum that I know!
So many different ideas to one goal: to make a good product for all!

I think the whole project must go on!

Kind regards,
Gabriel

2 Likes

Hi Davide,
You are right. the download.php file is right in the root folder of nethserver-manager and is acessible without authentication.
A better download library should be made. With session verification and with the date parameter sent via post. Maybe with token.

Feature:
Also it is possible to make the backup script add the date in the filename and set to only keep last 7 backup’s

it is usable now but it is not complete
If you see options for improving this please share :smile:

Best regards
Bogdan

I opened a new enhancement:

This can be an other enhancement. I guess it can help to rollback quickly a configuration error; could you also explain why it is useful?

BTW I think the backup-data already keeps the history of the configuration backup… @giacomo?

Hi Davide,
it is useful to have several backups.
if you for example configure something today and after two days you discovered that you have made a mistake in the configuration.
Now you can restore only the backup from yesterday and not from previous days.
So if you want to roll-back to the configuration from 4 days ago you can’t. :smile:

3 Likes

Hello everybody,

I’m agree with Bogdan.

I use something like this.

The Endian UTM has automatically configurable backup and it’s useful. You can configure what do you want to backup and imo, the best thing, how many backups do you want to keep.

I attach a picture. If you consider that break the policy of this forum, please delete it or tell me to delete.

Kind regards,
Gabriel

Well giving the nature and the proposal for new features I think that a re-thinking of the process has to be done.

For example the back-ups have to be saved in a location where the php scripts can acess them (to create the list and to be able to delete / download ).
That will mean that also the scripts that use the back-ups have to know the new location to be able to preform the rolback.
Something like:

  1. the scripts that generate the backup to be modified to add date to the filename.
  2. the backup-files to be placed in a location that the php scripts will be able to access them (read/download/delete)
  3. the php scripts to scan the directory of the back-ups and genearate a table with the files from that folder.
  4. for each generated link there will be butons to [Restore] [Download] [Delete]. (just like in the first picture attached by GG)

What do you think about this aproach ?

Best regards
Bogdan

@davidep @filippo_carletti what do you think about this proposal? Can we work on @Ctek code?

thanks to @GG_jr for the Endian example.

Hi Alessio,
I’ve worked a little on the backup script to make it create the backup filenames with the date in them, but i still need to modify the rest of the scripts to work with the generated files (i’ve made a git clone :smile: )

For example the script that is checking the conditions to trigger the backup is still work in progress. I’m not so good at perl and I’m researching how to do this checks on the backup folder.

After this, the backup-restore script has to be modified also to accept a filename as parameter :slight_smile:

Best regards
Bogdan

Show up your code! where is this clone?

EDIT: found thanks to @filippo_carletti hint :wink:

I’ve edited my post also (added link) :smile:

UPDATE:
Hi Guys, I’ve modified the scripts for backup (after learning a bit of perl :wink:) and put the code on Git.
Maybe somebody will try to validate it ? :smile:

TODO:
Now the rest of the files that need to be modified / created:
1 backup-restore
2 web interface to display a table with the files and the commands for each file

Feature proposal:
To have a field that will be set by the user regarding the number of backups to be keept [6] or [10] or [33]
.
This will probably require to store this setting in the DB and the rest of the scripts to read it (at the time when creating the backup to check that the total list will be [x] if it is greater then the set number ( x+1) then the last bkp file will be deleted)

Please let me know what you think
Best regards
Bogdan

1 Like

@davidep could take a look when he will came back from holiday :wink:

Well, that’s good :smile:
I have just updated some other files also :wink:

backup-config-info now scans all the files from the backup folder
backup-config-restore now accepts filename as parameter to be able to do specific restore

the code might be full of bugs but in tests it worked :wink:

TODO next:
The web interface that will make the restore and download possible.

Best regards
Bogdan

1 Like

Hi guys,
I’ve added to the view of the backup module a table that should show the backups from the folder.
( https://github.com/c-tek/nethserver-backup-config/commit/1052362c86a42de9483dda79f9d1d307abf95a02 )
Unfortunatelly I could not test the module on the server because I do not know how to compile the backupConfig.pm.

Maybe someone could tell more about this so I can go forward :smile:

Best regards
Bogdan

There’s no need to compile, it’s perl. I can’t comment on the html part of the patch.
@davidep?

The first thing I noticed is Bootstrap and Glyphicons, added as dependencies. I prefer not adding libraries into specific packages, such as nethserver-backup-config. Instead they should go into nethserver-httpd-admin.

Frankly, I’d like to not have new libraries at all, if possible :wink:

I can’t check the patch today. Please, @Ctek could you attach a screenshot of the resulting interface to have an idea of the visual requirements of your work? Perhaps we have alternative solutions to Bootstrap and Glyphicons!