<?php // Отключаем ограничение времени выполнения скрипта settimelimit(0); //…
- User
- Assistant
The issue with your script is that it attempts to use PHP's ZipArchive class to extract a .wpress file. However, .wpress files created by the All-in-One WP Migration plugin are not standard ZIP archives and cannot be extracted using ZipArchive.
Here’s how you can fix the problem and make your script work:
wpress-extractor ToolThe developers of the All-in-One WP Migration plugin provide a command-line tool called wpress-extractor specifically designed to extract .wpress files. You can download it from their official documentation:
Download Link: wpress-extractor
Steps to Use wpress-extractor:
Download the Tool:
Download the wpress-extractor executable for your operating system.
Grant Execute Permissions (if on Linux/Unix):
chmod +x wpress-extractor
Extract the .wpress File:
./wpress-extractor your-backup-file.wpress
This will extract the contents of the .wpress file into a folder in the same directory.
Move the Extracted Files:
Move the extracted files to your WordPress root directory ($wpRoot in your script).
Since the extraction is handled by wpress-extractor, you can remove or comment out the extraction part of your PHP script:
// Remove or comment out this section
/*
$zip = new ZipArchive;
if ($zip->open($backupFile) === TRUE) {
$zip->extractTo($wpRoot);
$zip->close();
echo "Файлы успешно распакованы.<br>";
} else {
die("Не удалось открыть архив.");
}
*/
database.sql ExistsAfter extraction, ensure that the database.sql file exists in your WordPress root directory. Your script uses this file to import the database.
Importing large SQL files using mysqli_multi_query can cause issues due to memory limits or other constraints. It's better to use a more robust method for importing the SQL file.
Here's an updated version of your database import logic:
// Importing the database
$sqlFile = $wpRoot . '/database.sql';
if (file_exists($sqlFile)) {
// Include WordPress config to get DB credentials
require_once($wpRoot . '/wp-config.php');
// Command to import SQL file
$command = "mysql -h " . DB_HOST . " -u " . DB_USER . " -p'" . DB_PASSWORD . "' " . DB_NAME . " < " . $sqlFile;
// Execute the command
system($command, $output);
if ($output === 0) {
echo "База данных успешно импортирована.<br>";
} else {
echo "Ошибка при импорте базы данных.<br>";
}
} else {
echo "Файл базы данных не найден.<br>";
}
Note: This code uses the mysql command-line tool to import the SQL file, which is more efficient for large files. Ensure that the PHP user has permission to execute system commands, and the mysql command is available on your server.
Here's the updated script:
<?php
// Отключаем ограничение времени выполнения скрипта
set_time_limit(0);
// Увеличиваем лимит памяти
ini_set('memory_limit', '1024M');
// Путь к файлу резервной копии
$backupFile = '/var/www/html/wordpress/wp-content/ai1wm-backups/livada-com-ua-20241004-124555-3345he.wpress';
// Путь к корневой директории WordPress
$wpRoot = '/var/www/html/wordpress';
// Проверяем наличие файла резервной копии
if (!file_exists($backupFile)) {
die("Файл резервной копии не найден.");
}
// Предполагаем, что архив уже распакован с помощью wpress-extractor
// Импортируем базу данных
$sqlFile = $wpRoot . '/database.sql';
if (file_exists($sqlFile)) {
// Подключаемся к базе данных
require_once($wpRoot . '/wp-config.php');
// Команда для импорта SQL файла
$command = "mysql -h " . DB_HOST . " -u " . DB_USER . " -p'" . DB_PASSWORD . "' " . DB_NAME . " < " . $sqlFile;
// Выполняем команду
system($command, $output);
if ($output === 0) {
echo "База данных успешно импортирована.<br>";
} else {
echo "Ошибка при импорте базы данных.<br>";
}
} else {
echo "Файл базы данных не найден.<br>";
}
echo "Импорт завершен. Пожалуйста, проверьте ваш сайт.";
?>
File Permissions: Ensure that the web server user has the necessary permissions to read/write files in the WordPress directory.
Database Credentials:
Double-check the database credentials in wp-config.php to ensure they are correct.
Backup Your Data: Always make sure to backup your current files and database before running restoration scripts.
Use the Plugin (Recommended):
If possible, the safest and most reliable method is to use the All-in-One WP Migration plugin within WordPress to import your .wpress file. This handles all the extraction and database import processes automatically.
By using the wpress-extractor tool to extract your .wpress file and adjusting your script accordingly, you should be able to restore your WordPress site successfully.