* Copyright (C) 2006-2021 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/admin/tools/dolibarr_export.php * \ingroup core * \brief Page to export database */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; $langs->load("admin"); $action = GETPOST('action', 'aZ09'); $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "date"; } if (empty($page) || $page == -1) { $page = 0; } $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $offset = $limit * $page; if (!$user->admin) { accessforbidden(); } /* * Actions */ if ($action == 'deletefile') { if (preg_match('/^backup\//', GETPOST('urlfile', 'alpha'))) { $file = $conf->admin->dir_output.'/backup/'.basename(GETPOST('urlfile', 'alpha')); $ret = dol_delete_file($file, 1); if ($ret) { setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); } } else { $file = $conf->admin->dir_output.'/documents/'.basename(GETPOST('urlfile', 'alpha')); $ret = dol_delete_file($file, 1); if ($ret) { setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs'); } else { setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); } } $action = ''; } /* * View */ $form = new Form($db); $formfile = new FormFile($db); $label = $db::LABEL; $type = $db->type; //var_dump($db); $help_url = 'EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad'; llxHeader('', '', $help_url); print '\n"; $title = $langs->trans("Backup"); print load_fiche_titre($title, '', 'title_setup'); //print_barre_liste($langs->trans("Backup"), '', '', '', '', '', $langs->trans("BackupDesc",DOL_DATA_ROOT), 0, 0, 'title_setup'); print '
'; print $langs->trans("BackupDesc", DOL_DATA_ROOT); print '
'; print '
'; print "\n"; print '
'; print ''; print ''; print ''; print '
1'; print ''; print $langs->trans("BackupDesc3", $dolibarr_main_db_name).'
'; //print $langs->trans("BackupDescY").'
'; print '
'; print '
'; print '
'; $title = $langs->trans("BackupDumpWizard"); print load_fiche_titre($title); print ''; print ''; print ''; print ''; print ''; print '
'; print $langs->trans("DatabaseName").' : '.$dolibarr_main_db_name.'
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print '
'; print '
'.$langs->trans("ExportMethod").''; if (in_array($type, array('mysql', 'mysqli'))) { print '
'; print ''; print '
'; print '
'; print '
'; print ''; print '
'; } elseif (in_array($type, array('pgsql'))) { print '
'; print ''; print '
'; } else { print 'No method available with database '.$label; } print '
'; print '
'; print '
'; print ''; print ''; print ''; print '
'; print ''; print '
'; print ''; print '
'; $prefix = 'dump'; $ext = '.sql'; if (in_array($type, array('mysql', 'mysqli'))) { $prefix = 'mysqldump'; $ext = 'sql'; } //if ($label == 'PostgreSQL') { // $prefix='pg_dump'; // $ext='dump'; //} if (in_array($type, array('pgsql'))) { $prefix = 'pg_dump'; $ext = 'sql'; } $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.dol_print_date(dol_now('gmt'), "dayhourlogsmall", 'tzuser').'.'.$ext; print ''; print '
'; print '
'; // Define compressions array $compression = array(); if (in_array($type, array('mysql', 'mysqli'))) { $compression['gz'] = array( 'function' => 'gzopen', 'id' => 'radio_compression_gzip', 'label' => $langs->trans("Gzip") ); // Not open source format. Must implement dol_compress function // $compression['zip']= array( // 'function' => 'dol_compress', // 'id' => 'radio_compression_zip', // 'label' => $langs->trans("FormatZip") // ); $compression['bz'] = array( 'function' => 'bzopen', 'id' => 'radio_compression_bzip', 'label' => $langs->trans("Bzip2") ); $compression['zstd'] = array( 'function' => 'zstd_compress', 'id' => 'radio_compression_zstd', 'label' => $langs->trans("Zstd") ); $compression['none'] = array( 'function' => '', 'id' => 'radio_compression_none', 'label' => $langs->trans("None") ); } else { $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") ); } // Show compression choices print '
'; print "\n"; print $langs->trans("Compression").':   '; $i = 0; foreach ($compression as $key => $val) { if (!$val['function'] || function_exists($val['function'])) { // Enabled export format $checked = ''; if ($key == 'gz') { $checked = ' checked'; } print ''; print ' '; } else { // Disabled export format print ''; print ' '; print ' ('.$langs->trans("NotAvailable").')'; } print '     '; $i++; } print '
'; print "\n"; print " \n"; print '
'; print '
'; print ''; print '
'; print '
'; if (!empty($_SESSION["commandbackuplastdone"])) { print '
'.$langs->trans("RunCommandSummary").':
'."\n"; print '
'."\n"; print '
'; //print $paramclear; // Now show result print ''.$langs->trans("BackupResult").': '; print $_SESSION["commandbackupresult"]; $_SESSION["commandbackuplastdone"] = ''; $_SESSION["commandbackuptorun"] = ''; $_SESSION["commandbackupresult"] = ''; } if (!empty($_SESSION["commandbackuptorun"])) { print '
'.$langs->trans("YouMustRunCommandFromCommandLineAfterLoginToUser", $dolibarr_main_db_user, $dolibarr_main_db_user).':
'."\n"; print '
'."\n"; print ajax_autoselect("commandbackuptoruntext", 0); print '
'; //print $paramclear; $_SESSION["commandbackuplastdone"] = ''; $_SESSION["commandbackuptorun"] = ''; $_SESSION["commandbackupresult"] = ''; } print "
\n"; print '
'; print "
\n"; print '
'; $filearray = dol_dir_list($conf->admin->dir_output.'/backup', 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1); $result = $formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'backup/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousDumpFiles"), '', 0, -1, '', '', 'ASC', 1, 0, -1, 'style="height:480px; overflow: auto;"'); print '
'; print '
'; print ''; print '
'; $title = $langs->trans("BackupZipWizard"); print "
\n"; print "\n"; print '
'; print ''; print ''; print ''; print '
2'; print ''; print $langs->trans("BackupDesc2", DOL_DATA_ROOT).'
'; print $langs->trans("BackupDescX").'

'; print '
'; print '
'; print load_fiche_titre($title); print '
'; $prefix = 'documents'; $ext = 'zip'; $file = $prefix.'_'.$dolibarr_main_db_name.'_'.dol_sanitizeFileName(DOL_VERSION).'_'.dol_print_date(dol_now('gmt'), "dayhourlogsmall", 'tzuser'); print '
'; print '
'; // Show compression choices // Example: With gz choice, you can compress in 5mn, a file of 2GB directory (after compression) with 10 Mb memory. print '
'; print "\n"; print $langs->trans("Compression").':   '; $filecompression = $compression; unset($filecompression['none']); $filecompression['zip'] = array('function' => 'dol_compress_dir', 'id' => 'radio_compression_zip', 'label' => $langs->trans("FormatZip")); $i = 0; foreach ($filecompression as $key => $val) { if (!$val['function'] || function_exists($val['function'])) { // Enabled export format $checked = ''; if ($key == 'gz') { $checked = ' checked'; } print ''; print ' '; } else // Disabled export format { print ''; print ' '; print ' ('.$langs->trans("NotAvailable").')'; } print '     '; $i++; } print '
'; print "\n"; print '
'; print '
'; print '
'; print '
'; print '
'; print '
'; print '
'; $filearray = dol_dir_list($conf->admin->dir_output.'/documents', 'files', 0, '', '', $sortfield, (strtolower($sortorder) == 'asc' ?SORT_ASC:SORT_DESC), 1); $result = $formfile->list_of_documents($filearray, null, 'systemtools', '', 1, 'documents/', 1, 0, $langs->trans("NoBackupFileAvailable"), 0, $langs->trans("PreviousArchiveFiles"), '', 0, -1, '', '', 'ASC', 1, 0, -1, 'style="height:250px; overflow: auto;"'); print '
'; print '
'; print '
'; print '
'; // End of page llxFooter(); $db->close();