Revision: 42611
Updated Code
at March 8, 2011 05:48 by leoj3n
Updated Code
<?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/ */ $options = array( 'cpanel' => array( '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 'ftp' => array( '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!\n"; // cron log exit; // exit script } // 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, 'Host: ' . $options['cpanel']['domain'] . " " ); fwrite( $socket, 'Authorization: Basic ' . base64_encode( $options['cpanel']['user'] . ':' . $options['cpanel']['pass'] ) . " " ); fwrite( $socket, "Connection: Close " ); $response = stream_get_contents( $socket ); // record cpanel response if ($options['log']) echo $response; // cron log fclose($socket); ?>
Revision: 42610
Updated Code
at March 8, 2011 05:47 by leoj3n
Updated Code
<?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/ */ /* $options = array( 'cpanel' => array( '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 'ftp' => array( '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!\n"; // cron log exit; // exit script } // 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, 'Host: ' . $options['cpanel']['domain'] . " " ); fwrite( $socket, 'Authorization: Basic ' . base64_encode( $options['cpanel']['user'] . ':' . $options['cpanel']['pass'] ) . " " ); fwrite( $socket, "Connection: Close " ); $response = stream_get_contents( $socket ); // record cpanel response if ($options['log']) echo $response; // cron log fclose($socket); ?>
Revision: 42609
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 8, 2011 05:27 by leoj3n
Initial Code
<?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/ */ $options = array( 'cpanel' => array( '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 'ftp' => array( '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!\n"; // cron log exit; // exit script } // 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, 'Host: ' . $options['cpanel']['domain'] . " " ); fwrite( $socket, 'Authorization: Basic ' . base64_encode( $options['cpanel']['user'] . ':' . $options['cpanel']['pass'] ) . " " ); fwrite( $socket, "Connection: Close " ); $response = stream_get_contents( $socket ); // record cpanel response if ($options['log']) echo $response; // cron log fclose($socket); ?>
Initial URL
http://www.justin-cook.com/wp/2006/12/27/automatic-cpanel-backup-domain-mysql-with-cron-php/
Initial Description
This is a php script to trigger a cpanel full backup to the servers home directory OR a remote ftp server
Initial Title
Automatic cPanel backup using cron
Initial Tags
backup
Initial Language
PHP