Aggiunto backup del solo database

This commit is contained in:
Luca 2024-03-04 02:07:58 +01:00
parent fd7a021605
commit 04f0d8a20c
2 changed files with 11 additions and 19 deletions

View File

@ -56,20 +56,16 @@ switch (filter('op')) {
case 'backup': case 'backup':
$ignore_dirs = []; $ignores = ['dirs' => [], 'files' => []];
/*if (!empty(filter('ignore_dirs'))){
$ignore_dirs = explode(',', filter('ignore_dirs'));
}*/
if (filter('exclude') == 'exclude_attachments'){ if (filter('exclude') == 'exclude_attachments'){
$ignore_dirs[] = 'files'; $ignores = ['dirs' => ['files']];
}else if (filter('exclude') == 'only_database'){ }else if (filter('exclude') == 'only_database'){
$ignore_dirs = ['vendor','update','templates','src','plugins','modules','logs','locale','lib','include','files','config','assets','api']; $ignores = ['dirs' => ['vendor','update','templates','src','plugins','modules','logs','locale','lib','include','files','config','assets','api'], 'files' => ['*.php','*.md','*.json','*.js','*.xml','.*']];
} }
try { try {
$result = Backup::create($ignore_dirs); $result = Backup::create($ignores);
if ($result) { if ($result) {
flash()->info(tr('Nuovo backup creato correttamente!')); flash()->info(tr('Nuovo backup creato correttamente!'));

View File

@ -145,16 +145,16 @@ class Backup
/** /**
* Esegue il backup del progetto. * Esegue il backup del progetto.
* *
* @param array $ignore_dirs Eventuali dirs da ignorare * @param array $ignores eventuali dirs o files da ignorare
* *
* @return bool * @return bool
*/ */
public static function create($ignore_dirs) public static function create($ignores)
{ {
self::checkSpace(); self::checkSpace();
$backup_dir = self::getDirectory(); $backup_dir = self::getDirectory();
$backup_name = tr(self::getNextName(), [ 'AAAAAAA' => ($ignore_dirs)? 'PARTIAL' : 'FULL' ]); $backup_name = tr(self::getNextName(), [ 'AAAAAAA' => ($ignores['dirs'] || $ignores['files'] )? 'PARTIAL' : 'FULL' ]);
set_time_limit(0); set_time_limit(0);
@ -162,8 +162,8 @@ class Backup
$database_file = self::getDatabaseDirectory().'/database.sql'; $database_file = self::getDatabaseDirectory().'/database.sql';
self::database($database_file); self::database($database_file);
// Percorsi da ignorare di default // Files e dirs da ignorare di default
$ignores = [ $default_ignores = [
'files' => [ 'files' => [
'config.inc.php', 'config.inc.php',
'*.lock', '*.lock',
@ -179,13 +179,9 @@ class Backup
], ],
]; ];
// Altri percorsi da ignorare $ignores = array_merge_recursive($ignores, $default_ignores);
if ($ignore_dirs){
foreach ((array) $ignore_dirs as $value) {
$ignores['dirs'][] = basename($value);
}
}
// Escludo la directory dei backup
if (string_starts_with($backup_dir, slashes(base_dir()))) { if (string_starts_with($backup_dir, slashes(base_dir()))) {
$ignores['dirs'][] = basename($backup_dir); $ignores['dirs'][] = basename($backup_dir);
} }