<?php 
$date = date('Y-m-j----H-i');

// Sauvegarde AXA
// Répertoire de destination des backups (chemin absolu !)
define('DIR_DEST', '/home/agencelujv/www/sauvegarde/AXA/');

// Paramètres de connexion à la base de données
define('DB_HOST', 'agencelujvsite.mysql.db');
define('DB_USER', 'agencelujvsite');
define('DB_PWD', 'Valerie0');
define('DB_NAME', 'agencelujvsite');

// Lancement du backup
system("mysqldump --host=".DB_HOST." --user=".DB_USER." --password=".DB_PWD." ".DB_NAME." > ".DIR_DEST.DB_NAME.".".$date.".sql");
system("gzip ".DIR_DEST.DB_NAME.".".$date.".sql");

//Suppression des vieux fichiers
/** define the directory **/
$dir = "/home/agencelujv/www/sauvegarde/AXA/"; // chemin absolu exemple:"/homez.xxxx/xxxxx/www/_archives/"

/*** cycle through all files in the directory ***/
foreach (glob($dir."*.gz") as $file) {

/*** if file is 30 days (2592000 seconds) old then delete it ***/
if (filemtime($file) < time() - 2592000) { //temps en seconde (30jours)
    unlink($file);
    }
}
?>