#!/usr/local/bin/php $fichier"); $jour = date('d-m-Y'); $heure = date("H_i_s"); $infos = $jour.'-'.$heure; $fichier = "backup_auto-" .$infos .".csv"; //////// modif le 30 Juin 2018 aaa // $chemin = '/homez.65/analogde/www/WORKAREA/WEBSITE/PROD/backup'; $chemin = '/homez.65/analogde/www/CHESS_ON/backup'; chdir($chemin); $files = scandir($chemin); // Count the number of files and store them inside the variable.. // Removing 2 because we do not count '.' and '..'. $num_files = count($files)-2; //echo " Total : " .$num_files; //echo "

"; //$time_ancien = 3 * 24 * 60 * 60; //listing_files("backup",$time_ancien); /* if( $num_files >= 95) { $path = './uploads/'; $days = 2; deleteOlderFiles($path,$days); } */ // DB_to_file($fichier); // $time_ancien = 3 * 24 * 60 * 60; // ancien("backup", $time_ancien); $fichier = "backup_bis-" .$infos .".txt"; $chemin = 'homez.65/analogde/www/WORKAREA/WEBSITE/PROD/backup'; //DB_to_file($chemin, $fichier); //$fp = fopen("oto", 'a+'); //fputs ($fp, "bkabka"); //fclose($fp); //chdir($chemin); //DB_to_file($fichier); //echo "Sauver les parties"; //echo "

"; backup_table(); chdir(".."); //echo "

"; //echo "Path : " .getcwd(); //echo "

"; //echo "Dump de la DB de chess 2022"; //echo "

"; dump_table(); //echo "Fin...."; //$fichier = '/homez.65/analogde/www/CHESS_2022/dump/dump_db_auto-'.$infos.'.sql'; //system("mysqldump --host=analogdepat.mysql.db --user=analogdepat --password=Un92pac007 --default-character-set=utf8 analogdepat clone_chessmaster_new clone_classement_new clone_evolution_new clone_parties_new clone_elo_affectation > $fichier"); //https://www.cluemediator.com/delete-files-older-than-x-days-or-after-x-amount-of-time-in-php function backup_table() { $jour = date('d-m-Y'); $heure = date("H_i_s"); $infos = $jour.'-'.$heure; $fichier = "backup_auto-" .$infos .".csv"; $chemin = '/homez.65/analogde/www/CHESS_ON/backup'; chdir($chemin); DB_to_file($fichier); $time_ancien = 30 * 24 * 60 * 60; remove_old_files("backup",$time_ancien); } function dump_table() { $jour = date('d-m-Y'); $heure = date("H_i_s"); $infos = $jour.'-'.$heure; $fichier = '/homez.65/analogde/www/CHESS_ON/dump/dump_db_auto-'.$infos.'.sql'; system("mysqldump --host=analogdepat.mysql.db --user=analogdepat --password=Un92pac007 --default-character-set=utf8 analogdepat clone_chessmaster_new clone_classement_new clone_evolution_new clone_parties_new clone_elo_affectation > $fichier"); // 24 * 3 = 72 fichiers $time_ancien = 30 * 24 * 60 * 60; remove_old_files("dump", $time_ancien); } function deleteOlderFiles($path,$days) { if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { $filelastmodified = filemtime($path . $file); if((time() - $filelastmodified) > $days*24*3600) { if(is_file($path . $file)) { unlink($path . $file); } } } closedir($handle); } } function ancien($path, $time_ancien) { chdir($path); $x = 21600; // 6 hours - 6*60*60 $x = 7 * 24 * 60 * 60; // 7 jours $current_time = time(); //$path = './uploads/'; //$files = glob($path.'/*.*'); $files = glob('*.*'); foreach($files as $file) { $file_creation_time = filemtime($file); $difference = $current_time - $file_creation_time; if(is_file($file)) { if ($difference >= $time_ancien) { unlink($file); //echo " *** " .$file; //echo "
"; } } } chdir(".."); } function remove_old_files($path, $time_ancien) { //echo "Ancien Path : " .getcwd(); //echo "

"; chdir($path); $current_time = time(); //echo "Path : " .getcwd(); //echo "

"; $cpt = 1; $files = glob('*.*'); foreach($files as $file) { $file_creation_time = filemtime($file); $difference = $current_time - $file_creation_time; if(is_file($file)) { //echo " *** " .$cpt ." " .$file ." " .$file_creation_time ." " .$time_ancien ." " .$difference; //echo "
"; $cpt++; if ($difference >= $time_ancien) // on prend les plus récent, 3 jours maxi { unlink($file); } } } } function DB_to_file($fichier) { //chdir($chemin); $sql = "SELECT * FROM clone_parties_new ORDER by date asc"; $results = mysql_query($sql); $nb_parties = mysql_num_rows($results); while($row = mysql_fetch_assoc($results)) { $blanc = $row['w_name']; $noir = $row['b_name']; $date = $row['date']; $resultat = $row['result']; $date_partie = date('d/m/Y', $date); if($resultat == 1) { $_score_blanc = 1; $_score_noir = 0; } if($resultat == 2) { $_score_blanc = 0; $_score_noir = 1; } if($resultat == 3) { $_score_blanc = 0.5; $_score_noir = 0.5; } $table_csv[0] = $date_partie; $table_csv[1] = $blanc; $table_csv[2] = $noir; $table_csv[3] = $_score_blanc; $table_csv[4] = $_score_noir; $table_fichier[] = $table_csv; } //echo getcwd(); $fp = fopen($fichier, 'a+'); for ($i=0; $i < $nb_parties; $i++) { $str_comma_separated = implode(";", $table_fichier[$i]); fputs ($fp, $str_comma_separated); if($i != $nb_parties - 1) fputs($fp, "\n"); } fclose($fp); //echo "Done"; } ?>