Skrypt, który używałem do pakowania/ robienia kopii zapasowej zawsze działał.
Od pewnego czasu nie potrafi poradzić sobie z prawdopodobnie wiekszą ilościa plików. Mimo to, że wcześniej wykonywał te kopie.
Przykładowo stosuje go do kopii wordpresów. teraz niestety, nie kończy wykonanie skryptu Tworząc plik:
2017-10-16-backup.zip.VVlEF3
czyli w którymś momencie kończy wykonywać się i nie dochodzi do:
$zip->close();
Tutaj kod skryptu:
Kod
<?php
session_start();
$when=date("Y-m-d");
if (!file_exists('../BackUp')) {
mkdir('../BackUp', 0777, true);
echo 'Utworzono katalog BackUp <br>';
}
else{
}
// Get real path for our folder
$rootPath = realpath('../');
// Initialize archive object
$zip = new ZipArchive();
$zip->open('../BackUp/'.$when.'-backup.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath));
//if((strpos($relativePath, 'BackUp') !== false) || (strpos($relativePath, 'zipper') !== false)){
//Dla m-foto/ bez sklepu
if((strpos($relativePath, 'BackUp') !== false) || (strpos($relativePath, 'zipper') !== false) ){
}
// Add current file to archive
else{
$_SESSION["show_path"]=$relativePath;
//echo $relativePath."<br>";
echo '<pre>' . print_r($_SESSION["show_path"], TRUE) . '</pre>';
$zip->addFile($filePath, $relativePath);
}
}
}
// Zip archive will be created only after closing object
$zip->close();
echo "BackUp plików zakończony";
?>
session_start();
$when=date("Y-m-d");
if (!file_exists('../BackUp')) {
mkdir('../BackUp', 0777, true);
echo 'Utworzono katalog BackUp <br>';
}
else{
}
// Get real path for our folder
$rootPath = realpath('../');
// Initialize archive object
$zip = new ZipArchive();
$zip->open('../BackUp/'.$when.'-backup.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath));
//if((strpos($relativePath, 'BackUp') !== false) || (strpos($relativePath, 'zipper') !== false)){
//Dla m-foto/ bez sklepu
if((strpos($relativePath, 'BackUp') !== false) || (strpos($relativePath, 'zipper') !== false) ){
}
// Add current file to archive
else{
$_SESSION["show_path"]=$relativePath;
//echo $relativePath."<br>";
echo '<pre>' . print_r($_SESSION["show_path"], TRUE) . '</pre>';
$zip->addFile($filePath, $relativePath);
}
}
}
// Zip archive will be created only after closing object
$zip->close();
echo "BackUp plików zakończony";
?>
Może ktoś wie dlaczego tak się dzieje?