$WebDAV = [ 'login'=>'', 'password'=>'', 'url'=>'https://webdav.yandex.ru/backups/sites/',// 'url'=>'https://webdav.cloud.mail.ru/backups/sites/',// Mail.Ru ];
The path to the cloud and the path to the target folder must be specified entirely. The folder where you plan to add your precious archives should be created independently in advance. I checked, and it is for sure that she will not be able to appear automatically. If you do not, the download will still go. In the case of Yandex, judging by the weight of the result, the downloaded files are simply glued together into one large one. In the case of Mail.Ru nothing appears. Mandatory closing slash. $backupPath
$databases = [['login' => '', 'password' => '', 'dbname' => '']];
'name' => 'site1.ru', 'path' => '/var/www/site1.ru', 'exclude' => []
'exclude' => [ $backupPath, // , '/var/www/site2.ru/temp' // - ]
site1.ru.2013-12-20.zip
$date = date('Ym-d');
on $date = date('YmdHi-s');
and then the date will be with the time up to seconds. $WebDAV = [ 'login'=>'', 'password'=>'', //url , //'url'=>'https://webdav.yandex.ru/backups/sites/',// , . 'url'=>'https://webdav.cloud.mail.ru/backups/sites/',// , . ]; $backupPath = 'path to backups'; //, , WebDAV $databases = [['login' => '', 'password' => '', 'dbname' => '']]; $sites = [ // : [ 'name' => 'site1.ru', 'path' => '/var/www/site1.ru', 'exclude' => [] ], // ['name' => 'site2.ru', 'path' => '.', // 'path' => '.' , . 'exclude' => [ // - , . , . $backupPath, // , '/var/www/site2.ru/temp' // - ] ], ]; // . ///////////////////////////////////////////////////////////////////////////////////////// // , , . . //. , . // . $date = date('Ym-d'); $errors = []; $success = []; $files_to_send = []; foreach ($databases as $db) { $filename = "$backupPath/bases/{$db['dbname']}.$date.sql.gz"; $output = `mysqldump --user={$db['login']} --password={$db['password']} {$db['dbname']} | gzip -f > $filename`; if (!file_exists($filename)) { $errors[] = 'Dump ' . $db['dbname'] . ' failed: ' . $output; } else { $success[] = 'DB ' . $db['dbname'] . ' dumped'; $files_to_send[] = $filename; } } foreach ($sites as $site) { $filename = "$backupPath/files/{$site['name']}.$date.zip"; $exclude = ''; if ($site['exclude']) { $exclude = '-x ' . implode('\* -x ', $site['exclude']) . '\*'; } $cmd = "zip -r \"$filename\" {$site['path']} $exclude"; echo $cmd . "<br>\n"; $output = `$cmd`; if (!file_exists($filename)) { $errors[] = 'Site backup ' . $site['name'] . ' failed: ' . $output; } else { $success[] = 'Site ' . $site['name'] . ' saved'; $files_to_send[] = $filename; } } foreach ($errors as $e) { echo ': ' . $e . "<br>\n"; } echo "<br>\n"; foreach ($success as $s) { echo ': ' . $s . "<br>\n"; } echo "<br>\n"; echo " :<br>\n"; foreach ($files_to_send as $f) { echo $f . "<br>\n"; } echo "<br>\n"; if (!empty($files_to_send)) { foreach ($files_to_send as $file) { echo shell_exec("curl --user {$WebDAV['login']}:{$WebDAV['password']} -T \"$file\" {$WebDAV['url']}") . "<br>\n";// , -k } }
Source: https://habr.com/ru/post/206898/
All Articles