使用cron的cPanel自动备份
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用cron的cPanel自动备份相关的知识,希望对你有一定的参考价值。
This is a php script to trigger a cpanel full backup to the servers home directory OR a remote ftp server
<?php /* * fullbackup.php * This is a php script to trigger a cpanel full backup to the servers home directory OR a remote ftp server * KEEP ACCESS TO THIS FILE SECURE! * Because this file contains passwords, it is safest located in the highest level root above /www/ or /public_html/ */ 'user' => '', // cpanel username 'pass' => '', // cpanel password 'domain' => '.com', // address to server running cpanel 'skin' => 'rvskin' ), // 'rvskinlight' for cpanel at https://example.com:2083/frontend/rvskinlight/index.html 'enabled' => false, // true: backup to a remote server using settings below, false: ignore settings below and backup to home directory 'user' => '', // ftp username 'pass' => '', // ftp password 'host' => 'ftp.example.com', // address to ftp server 'mode' => 'passiveftp', // must be 'ftp', 'passiveftp' (most common), or 'scp' 'port' => '21', // usually '21' for passiveftp 'dir' => '' ), // (optional) existing subdirectory on ftp server 'email' => '@gmail.com', // (optional) an email will be sent to this address when the backup is finished 'ssl' => false, // must be true if this script is not on the same server as cpanel 'log' => false ); // output error/success messages to cron log? $socket = fsockopen( ($options['ssl'] ? 'ssl:' : '') . $options['cpanel']['domain'], ($options['ssl'] ? 2083 : 2082) ); if( !$socket ) { if ($options['log']) echo "Failed to open socket connection... Exiting script! "; // cron log } // generate specific query for remote server or home directory if ($options['ftp']['enabled']) $query = 'dest=' . $options['ftp']['mode'] . '&server=' . $options['ftp']['host'] . '&user=' . $options['ftp']['user'] . '&pass=' . $options['ftp']['pass'] . '&port=' . $options['ftp']['port']. '&rdir=' . $options['ftp']['dir']; else $query = 'dest=homedir'; // tack on the variables required by any query $query .= '&email=' . $options['email'] . '&submit=Generate Backup'; // simluate post to 'dofullbackup.html' in cpanel fwrite( $socket, 'POST /frontend/' . $options['cpanel']['skin'] . '/backup/dofullbackup.html?' . $query . " HTTP/1.0 " ); " ); fwrite( $socket, 'Authorization: Basic ' . base64_encode( $options['cpanel']['user'] . ':' . $options['cpanel']['pass'] ) . " " ); " ); if ($options['log']) echo $response; // cron log ?>
以上是关于使用cron的cPanel自动备份的主要内容,如果未能解决你的问题,请参考以下文章
Cron mysqldump,无法读取“/etc/my.cnf.d”的目录(错误代码:2)
PHP 使用PHP将自动cPanel完整站点备份到异地FTP