2024-03-17 12:46:38 +01:00
|
|
|
<?php
|
|
|
|
// Creation du ZIP
|
|
|
|
$filter = $filter = ['backup', 'tmp'];
|
2024-03-17 12:49:55 +01:00
|
|
|
$fileName = date('Y-m-d-H-i-s', time()) . '-rolling-backup.zip';
|
2024-03-17 12:46:38 +01:00
|
|
|
$zip = new ZipArchive();
|
|
|
|
$zip->open('../../../../site/backup/' . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
|
|
|
$directory = '../../../../site';
|
|
|
|
$files = new RecursiveIteratorIterator(
|
|
|
|
new RecursiveCallbackFilterIterator(
|
|
|
|
new RecursiveDirectoryIterator(
|
|
|
|
$directory,
|
|
|
|
RecursiveDirectoryIterator::SKIP_DOTS
|
|
|
|
),
|
|
|
|
function ($fileInfo, $key, $iterator) use ($filter) {
|
|
|
|
return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
foreach ($files as $name => $file) {
|
|
|
|
if (!$file->isDir()) {
|
|
|
|
$filePath = $file->getRealPath();
|
|
|
|
$relativePath = substr($filePath, strlen(realpath($directory)) + 1);
|
|
|
|
$zip->addFile($filePath, $relativePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$zip->close();
|