Skip to content
Snippets Groups Projects
Commit a66985a2 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Restore backup feature

parent 9037d2be
No related branches found
No related tags found
No related merge requests found
...@@ -77,17 +77,22 @@ if (file_exists($xmlfile)) ...@@ -77,17 +77,22 @@ if (file_exists($xmlfile))
$xml = simplexml_load_file($xmlfile); $xml = simplexml_load_file($xmlfile);
if ($xml) if ($xml)
{ {
$ret = getFilesUpdated($xml->dolibarr_root_dir[0]); // Fill array $file_list $file_list = array();
$ret = getFilesUpdated($file_list, $xml->dolibarr_root_dir[0]); // Fill array $file_list
print '<table class="noborder">'; print '<table class="noborder">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>' . $langs->trans("FilesMissing") . '</td>'; print '<td>' . $langs->trans("FilesMissing") . '</td>';
print '<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
print '</tr>'."\n"; print '</tr>'."\n";
$var = true; $var = true;
foreach ($file_list['missing'] as $file) $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
foreach ($tmpfilelist as $file)
{ {
$var = !$var; $var = !$var;
print '<tr ' . $bc[$var] . '>'; print '<tr ' . $bc[$var] . '>';
print '<td>'.$file.'</td>' . "\n"; print '<td>'.$file['filename'].'</td>' . "\n";
print '<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
print "</tr>\n"; print "</tr>\n";
} }
print '</table>'; print '</table>';
...@@ -97,17 +102,22 @@ if (file_exists($xmlfile)) ...@@ -97,17 +102,22 @@ if (file_exists($xmlfile))
print '<table class="noborder">'; print '<table class="noborder">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>' . $langs->trans("FilesUpdated") . '</td>'; print '<td>' . $langs->trans("FilesUpdated") . '</td>';
print '<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
print '<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
print '<td align="right">' . $langs->trans("Size") . '</td>'; print '<td align="right">' . $langs->trans("Size") . '</td>';
print '<td align="center">' . $langs->trans("DateModification") . '</td>'; print '<td align="right">' . $langs->trans("DateModification") . '</td>';
print '</tr>'."\n"; print '</tr>'."\n";
$var = true; $var = true;
foreach ($file_list['updated'] as $file) $tmpfilelist = dol_sort_array($file_list['updated'], 'filename');
foreach ($tmpfilelist as $file)
{ {
$var = !$var; $var = !$var;
print '<tr ' . $bc[$var] . '>'; print '<tr ' . $bc[$var] . '>';
print '<td>'.$file.'</td>' . "\n"; print '<td>'.$file['filename'].'</td>' . "\n";
print '<td align="right">'.dol_print_size(dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file)).'</td>' . "\n"; print '<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
print '<td align="center">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file),'dayhour').'</td>' . "\n"; print '<td align="center">'.$file['md5'].'</td>' . "\n";
print '<td align="right">'.dol_print_size(dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename'])).'</td>' . "\n";
print '<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
print "</tr>\n"; print "</tr>\n";
} }
print '</table>'; print '</table>';
...@@ -124,34 +134,36 @@ $db->close(); ...@@ -124,34 +134,36 @@ $db->close();
/** /**
* Function to get list of updated or modified files * Function to get list of updated or modified files.
* $file_list is used as global variable
* *
* @param array $file_list Array for response
* @param SimpleXMLElement $dir SimpleXMLElement of files to test * @param SimpleXMLElement $dir SimpleXMLElement of files to test
* @param string $path Path of file * @param string $path Path of file
* @return array Array of filenames * @return array Array of filenames
*/ */
function getFilesUpdated(SimpleXMLElement $dir, $path = '') function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path = '')
{ {
global $file_list;
$exclude = 'install'; $exclude = 'install';
foreach ($dir->md5file as $file) foreach ($dir->md5file as $file)
{ {
$filename = $path.$file['name']; $filename = $path.$file['name'];
if (preg_match('#'.$exclude.'#', $filename)) if (preg_match('#'.$exclude.'#', $filename)) continue;
continue;
if (!file_exists(DOL_DOCUMENT_ROOT.'/'.$filename)) { if (!file_exists(DOL_DOCUMENT_ROOT.'/'.$filename))
$file_list['missing'][] = $filename; {
} else { $file_list['missing'][] = array('filename'=>$filename, 'expectedmd5'=>(string) $file);
}
else
{
$md5_local = md5_file(DOL_DOCUMENT_ROOT.'/'.$filename); $md5_local = md5_file(DOL_DOCUMENT_ROOT.'/'.$filename);
if ($md5_local != (string) $file) if ($md5_local != (string) $file) $file_list['updated'][] = array('filename'=>$filename, 'expectedmd5'=>(string) $file, 'md5'=>(string) $md5_local);
$file_list['updated'][] = $filename;
} }
} }
foreach ($dir->dir as $subdir) foreach ($dir->dir as $subdir) getFilesUpdated($file_list, $subdir, $path.$subdir['name'].'/');
getFilesUpdated($subdir, $path.$subdir['name'].'/');
return $file_list; return $file_list;
} }
<?php <?php
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@capnetworks.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -66,6 +66,8 @@ $form=new Form($db); ...@@ -66,6 +66,8 @@ $form=new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$label=$db::LABEL; $label=$db::LABEL;
$type=$db->type;
//var_dump($db);
$help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad'; $help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
llxHeader('','',$help_url); llxHeader('','',$help_url);
...@@ -101,8 +103,8 @@ jQuery(document).ready(function() { ...@@ -101,8 +103,8 @@ jQuery(document).ready(function() {
}); });
<?php <?php
if ($label == 'MySQL') print 'jQuery("#radio_dump_mysql").click();'; if (in_array($type, array('mysql', 'mysqli'))) print 'jQuery("#radio_dump_mysql").click();';
if ($label == 'PostgreSQL') print 'jQuery("#radio_dump_postgresql").click();'; if (in_array($type, array('pgsql'))) print 'jQuery("#radio_dump_postgresql").click();';
?> ?>
}); });
</script> </script>
...@@ -133,7 +135,7 @@ print '<br>'; ...@@ -133,7 +135,7 @@ print '<br>';
print_titre($title?$title:$langs->trans("BackupDumpWizard")); print_titre($title?$title:$langs->trans("BackupDumpWizard"));
print '<table width="100%" class="'.($useinecm?'nobordernopadding':'liste').'">'; print '<table width="100%" class="'.($useinecm?'nobordernopadding':'liste').' nohover">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b><br>'; print $langs->trans("DatabaseName").' : <b>'.$dolibarr_main_db_name.'</b><br>';
...@@ -148,7 +150,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">'; ...@@ -148,7 +150,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
<div id="div_container_exportoptions"> <div id="div_container_exportoptions">
<fieldset id="exportoptions"><legend><?php echo $langs->trans("ExportMethod"); ?></legend> <fieldset id="exportoptions"><legend><?php echo $langs->trans("ExportMethod"); ?></legend>
<?php <?php
if ($label == 'MySQL') if (in_array($type, array('mysql', 'mysqli')))
{ {
?> ?>
<div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" /> <div class="formelementrow"><input type="radio" name="what" value="mysql" id="radio_dump_mysql" />
...@@ -160,7 +162,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">'; ...@@ -160,7 +162,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
</div> </div>
<?php <?php
} }
else if ($label == 'PostgreSQL') else if (in_array($type, array('pgsql')))
{ {
?> ?>
<div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" /> <div class="formelementrow"><input type="radio" name="what" value="postgresql" id="radio_dump_postgresql" />
...@@ -182,7 +184,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">'; ...@@ -182,7 +184,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
<div id="div_container_sub_exportoptions"> <div id="div_container_sub_exportoptions">
<?php <?php
if ($label == 'MySQL') if (in_array($type, array('mysql', 'mysqli')))
{ {
?> <!-- Fieldset mysqldump --> ?> <!-- Fieldset mysqldump -->
<fieldset id="mysql_options"><legend><?php echo $langs->trans("MySqlExportParameters"); ?></legend> <fieldset id="mysql_options"><legend><?php echo $langs->trans("MySqlExportParameters"); ?></legend>
...@@ -317,7 +319,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">'; ...@@ -317,7 +319,7 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
<?php <?php
} }
if ($label == 'PostgreSQL') if (in_array($type, array('pgsql')))
{ {
?> <!-- Fieldset pg_dump --> ?> <!-- Fieldset pg_dump -->
<fieldset id="postgresql_options"><legend><?php echo $langs->trans("PostgreSqlExportParameters"); ?></legend> <fieldset id="postgresql_options"><legend><?php echo $langs->trans("PostgreSqlExportParameters"); ?></legend>
...@@ -382,9 +384,9 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">'; ...@@ -382,9 +384,9 @@ print '<tr '.$bc[false].'><td style="padding-left: 8px">';
value="<?php value="<?php
$prefix='dump'; $prefix='dump';
$ext='.sql'; $ext='.sql';
if ($label == 'MySQL') { $prefix='mysqldump'; $ext='sql'; } if (in_array($type, array('mysql', 'mysqli'))) { $prefix='mysqldump'; $ext='sql'; }
//if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; } //if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='dump'; }
if ($label == 'PostgreSQL') { $prefix='pg_dump'; $ext='sql'; } if (in_array($type, array('pgsql'))) { $prefix='pg_dump'; $ext='sql'; }
$file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext; $file=$prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.strftime("%Y%m%d%H%M").'.'.$ext;
echo $file; echo $file;
?>" /> <br> ?>" /> <br>
...@@ -394,7 +396,7 @@ echo $file; ...@@ -394,7 +396,7 @@ echo $file;
// Define compressions array // Define compressions array
$compression=array(); $compression=array();
if ($label == 'MySQL') if (in_array($type, array('mysql', 'mysqli')))
{ {
$compression['none'] = array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None")); $compression['none'] = array('function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None"));
$compression['gz'] = array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip")); $compression['gz'] = array('function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip"));
......
...@@ -1023,7 +1023,7 @@ NoEventOrNoAuditSetup=No security event has been recorded yet. This can be norma ...@@ -1023,7 +1023,7 @@ NoEventOrNoAuditSetup=No security event has been recorded yet. This can be norma
NoEventFoundWithCriteria=No security event has been found for such search criterias. NoEventFoundWithCriteria=No security event has been found for such search criterias.
SeeLocalSendMailSetup=See your local sendmail setup SeeLocalSendMailSetup=See your local sendmail setup
BackupDesc=To make a complete backup of Dolibarr, you must: BackupDesc=To make a complete backup of Dolibarr, you must:
BackupDesc2=Save content of documents directory (<b>%s</b>) that contains all uploaded and generated files (you can make a zip for example). BackupDesc2=Save content of documents directory (<b>%s</b>) that contains all uploaded and generated files (So it includes all dump files generated at step 1).
BackupDesc3=Save content of your database (<b>%s</b>) into a dump file. For this, you can use following assistant. BackupDesc3=Save content of your database (<b>%s</b>) into a dump file. For this, you can use following assistant.
BackupDescX=Archived directory should be stored in a secure place. BackupDescX=Archived directory should be stored in a secure place.
BackupDescY=The generated dump file should be stored in a secure place. BackupDescY=The generated dump file should be stored in a secure place.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment