Sauvegarde SQL
This commit is contained in:
@@ -123,7 +123,8 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
case 'stats':
|
case 'stats':
|
||||||
if ($user->rankIsHigher("moderator")) {
|
if ($user->rankIsHigher("moderator")) {
|
||||||
$head['title'] = "Statistiques";
|
$head['title'] = "Statistiques";
|
||||||
$report = $config['abs_root_folder'].'report.html';
|
|
||||||
|
$report = $config['abs_root_folder'].'tmp/report.html';
|
||||||
$files = glob('/var/log/nginx/kabano.org-access.log*.gz');
|
$files = glob('/var/log/nginx/kabano.org-access.log*.gz');
|
||||||
$command = '/bin/bash -c \'(zcat '.implode(' ', $files).' && cat /var/log/nginx/kabano.org-access.log.1) | goaccess --log-format=COMBINED --no-progress -o '.escapeshellarg($report).' - \' 2>&1';
|
$command = '/bin/bash -c \'(zcat '.implode(' ', $files).' && cat /var/log/nginx/kabano.org-access.log.1) | goaccess --log-format=COMBINED --no-progress -o '.escapeshellarg($report).' - \' 2>&1';
|
||||||
$output = shell_exec($command);
|
$output = shell_exec($command);
|
||||||
@@ -134,6 +135,37 @@ if(isset($controller->splitted_url[1]) && $user->rankIsHigher("moderator")) {
|
|||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'sql-backup':
|
||||||
|
if ($user->rankIsHigher("administrator")) {
|
||||||
|
$head['title'] = "Export SQL";
|
||||||
|
|
||||||
|
if(isset($controller->splitted_url[2]) && $controller->splitted_url[2]=='delete' && isset($controller->splitted_url[3])) {
|
||||||
|
unlink($config['abs_root_folder'].'tmp/'.$controller->splitted_url[3]);
|
||||||
|
$output = Array();
|
||||||
|
$backup_file = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Nom du fichier de sauvegarde
|
||||||
|
$timestamp = date('Ymd_His');
|
||||||
|
$filename = $timestamp.'_backup.sql';
|
||||||
|
$backup_file = $config['abs_root_folder'].'tmp/'.$filename;
|
||||||
|
|
||||||
|
// Construction de la commande pg_dump
|
||||||
|
$cmd = 'PGPASSWORD="'.$config['SQL_pass'].'" pg_dump -h '.$config['SQL_host'].' -U '.$config['SQL_user'].' -F c -b -v -f "'.$backup_file.'" '.$config['SQL_db'].' 2>&1';
|
||||||
|
|
||||||
|
$output = [];
|
||||||
|
$return_var = 0;
|
||||||
|
exec($cmd, $output, $return_var);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql_files = glob($config['abs_root_folder'].'tmp/*.sql');
|
||||||
|
|
||||||
|
include ($config['views_folder']."d.admin.sql-dump.html");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$notfound = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$notfound = 1;
|
$notfound = 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ small {
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
margin: 5px 10px;
|
margin: 5px 10px;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<? if($user->rankIsHigher("administrator")) { ?>
|
<? if($user->rankIsHigher("administrator")) { ?>
|
||||||
<a href="<?=$config['rel_root_folder']?>admin/git-pull" class="button"><i class="fas fa-sync-alt"></i> Mettre à jour</a> <small>Met à jour le logiciel depuis le dépôt GIT.</small><br><br>
|
<a href="<?=$config['rel_root_folder']?>admin/git-pull" class="button"><i class="fas fa-sync-alt"></i> Mettre à jour</a> <small>Met à jour le logiciel depuis le dépôt GIT.</small><br><br>
|
||||||
|
<a href="<?=$config['rel_root_folder']?>admin/sql-backup" class="button"><i class="fas fa-file-export"></i> Sauvegarde SQL</a><small>Génère un dump SQL téléchargeable.</small><br><br>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
<? if($user->rankIsHigher("moderator")) { ?>
|
<? if($user->rankIsHigher("moderator")) { ?>
|
||||||
<a href="<?=$config['rel_root_folder']?>admin/logs" class="button"><i class="fas fa-history"></i> Voir les logs</a> <small>Permet d'accéder aux 200 dernières lignes des logs bruts des actions sur la base de données.</small><br><br>
|
<a href="<?=$config['rel_root_folder']?>admin/logs" class="button"><i class="fas fa-history"></i> Voir les logs</a> <small>Permet d'accéder aux 200 dernières lignes des logs bruts des actions sur la base de données.</small><br><br>
|
||||||
|
|||||||
39
views/d.admin.sql-dump.html
Normal file
39
views/d.admin.sql-dump.html
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
|
||||||
|
<? include('blocks/d.head.html'); ?>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<? include('blocks/d.nav.html'); ?>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h1><?=$head['title']?></h1>
|
||||||
|
<br>
|
||||||
|
<pre><?
|
||||||
|
foreach($output as $line) {
|
||||||
|
echo $line."<br>";
|
||||||
|
}
|
||||||
|
?></pre>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<? if (file_exists($backup_file ?? '')) { ?>
|
||||||
|
<a href='<?=$config['rel_root_folder']?>tmp/<?=$filename?>' target='_blank'><i class="fas fa-file-export"></i> Télécharger le DUMP généré</a>
|
||||||
|
<? } else { ?>
|
||||||
|
Le DUMP n'a pas été généré
|
||||||
|
<? } ?>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<h4>Archives des anciennes sauvegardes</h4>
|
||||||
|
<ul style="padding: 1em 0 1em 40px;">
|
||||||
|
<? foreach($sql_files as $file) { ?>
|
||||||
|
<li style="padding: 0 0 0.2em 0;"><?=basename($file)?> - <a href='<?=$config['rel_root_folder']?>tmp/<?=basename($file)?>' target='_blank'><i class="fas fa-download"></i> Télécharger</a> - <a href='<?=$config['rel_root_folder']?>admin/sql-backup/delete/<?=basename($file)?>'><i class="fas fa-trash"></i> Effacer</a></li>
|
||||||
|
<? } ?>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<? include('blocks/d.footer.html'); ?>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
?></pre>
|
?></pre>
|
||||||
<br>
|
<br>
|
||||||
<? if (file_exists($report)) { ?>
|
<? if (file_exists($report)) { ?>
|
||||||
<a href='/report.html' target='_blank'><i class="fas fa-chart-line"></i> Voir le rapport</a>
|
<a href='<?=$config['rel_root_folder']?>tmp/report.html' target='_blank'><i class="fas fa-chart-line"></i> Voir le rapport</a>
|
||||||
<? } else { ?>
|
<? } else { ?>
|
||||||
Echec de la commande
|
Echec de la commande
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user