оригинал
http://www.fractalizer.ru/frpost_356/php-script-to-backup-all-databases/
{$backupPath}/$database.$dateStr.sql.gz", $output, $result);
if($result) {
echo("Error dumping database $backupPath: $result");
}
}
//Deleting old backups
exec('find '.$backupPath.' -mtime '.$maxdaysold.' -name "*.sql.gz" -exec rm {} \\;', $output, $result);
if($result) {
echo("Error removing old database backups!");
}
echo('Database backup succeeded. Time elapsed: '.(time() - $timeStarted).' sec.');
echo("\n");