I want to archive the previous 4 backup files in my backup dir and delete the oldest when making a new one, automatically of course! Here's what I have:
This doesn't delete anything though, it just keeps adding the new backup to the archive.PHP Code:$numfile = 0;
$dir = '/home/site/backups/';
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if(is_file($file))
{
$oldest = $file;
if (filemtime($file) > filemtime($oldest))
{
$oldest = $file;
}
if ($numfile >= 5)
{
unlink($file);
}
$numfile++;
}
}
closedir($dh);
}
}
//then run a new backup
// Backup directory without trailing /
$backup_path = '/home/site/backups;
echo '<br /><p class="content">Backing up the database....<br /><br />;
$exec = system("mysqldump --add-drop-table -c -umyusername -pmypass mydb>$backup_path/backup_".$today.".sql");
Can anyone see trouble with this? Thanks![]()


LinkBack URL
About LinkBacks




Reply With Quote


Bookmarks