From 23fe19bfbf240ca60938c68ef7967abfd23a11b8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Sep 2024 18:53:06 +0200 Subject: [PATCH] Clean code --- scripts/master_move_instance.php | 47 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/scripts/master_move_instance.php b/scripts/master_move_instance.php index 46248785..97050f65 100755 --- a/scripts/master_move_instance.php +++ b/scripts/master_move_instance.php @@ -662,31 +662,35 @@ // First we get the files of the source to move -$command="rsync"; -$param=array(); +$command = "rsync"; +$param = array(); //if (! in_array($mode, array('confirm', 'confirmredirect', 'confirmmaintenance'))) $param[]="-n"; //$param[]="-a"; if (! in_array($mode, array('diff','diffadd','diffchange'))) { - $param[]="-rlt"; + $param[] = "-rlt"; } else { - $param[]="-rlD"; - $param[]="--modify-window=1000000000"; - $param[]="--delete -n"; + $param[] = "-rlD"; + $param[] = "--modify-window=1000000000"; + $param[] = "-n"; } + //$param[]="-v"; if (empty($createthirdandinstance)) { - $param[]="-u"; + $param[] = "-u"; } // If we have just created instance, we overwrite file during rsync -$param[]="--exclude .buildpath"; -$param[]="--exclude .git"; -$param[]="--exclude .gitignore"; -$param[]="--exclude .settings"; -$param[]="--exclude .project"; -$param[]="--exclude *.pdf_preview.png"; -$param[]="--exclude htdocs/conf/conf.php"; -$param[]="--exclude glpi_config/config_db.php"; -$param[]="--exclude htdocs/inc/downstream.php"; -$param[]="-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'"; +$param[] = "--exclude .buildpath"; +$param[] = "--exclude .git"; +$param[] = "--exclude .gitignore"; +$param[] = "--exclude .settings"; +$param[] = "--exclude .project"; +$param[] = "--exclude *.pdf_preview.png"; +$param[] = "--exclude htdocs/conf/conf.php"; +$param[] = "--exclude glpi_config/config_db.php"; +$param[] = "--exclude htdocs/inc/downstream.php"; + +$param[] = "--delete"; + +$param[] = "-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'"; $param[]=$oldosuser.'@'.$oldoshost.":".$sourcedir.'/*'; $param[]=$tmptargetdir; @@ -737,11 +741,10 @@ //$param[]="-a"; if (! in_array($mode, array('diff','diffadd','diffchange'))) { $param[] = "-rlt"; - $param[] = "--delete"; // Delete existing files not into source and not into the --exclude parameters } else { $param[] = "-rlD"; $param[] = "--modify-window=1000000000"; - $param[] = "--delete -n"; + $param[] = "-n"; } //$param[] = "-v"; if (empty($createthirdandinstance)) { @@ -755,6 +758,12 @@ $param[] = "--exclude htdocs/conf/conf.php"; $param[] = "--exclude glpi_config/config_db.php"; $param[] = "--exclude htdocs/inc/downstream.php"; + +if (!$overwriteexistinginstance) { + // There is no existing instance so no risk to delete data we want to keep. So we can use --delete. + $param[] = "--delete"; // Delete existing files not into source and not into the --exclude parameters +} + $param[] = "-e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'"; $param[] = $sourcedir.'/';