hello, l have a host service in hostgator with cpanel. l am curiouse if its possible to make automatic backups without payning to hostgator. is there a script that makes backup of my files and database... ?
Create a file named fullbackup.php on the home folder of your account with this code (modify the Cpanel and FTP user and password to yours): <?php // PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server. // This script contains passwords. KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/) // ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED ********* // Info required for cPanel access $cpuser = "user"; // Username used to login to CPanel $cppass = "password"; // Password used to login to CPanel $domain = "domain.com"; // Domain name where CPanel is run $skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme // Info required for FTP host $ftpuser = "user"; // Username for FTP account $ftppass = "password"; // Password for FTP account $ftphost = "host"; // Full hostname or IP address for FTP host $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive) // Notification information $notifyemail = "your@email.com"; // Email address to send results // Secure or non-secure mode $secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP // Set to 1 to have web page result appear in your cron log $debug = 0; // *********** NO CONFIGURATION ITEMS BELOW THIS LINE ********* if ($secure) { $url = "ssl://".$domain; $port = 2083; } else { $url = $domain; $port = 2082; } $socket = fsockopen($url,$port); if (!$socket) { echo "Failed to open socket connection… Bailing out!\n"; exit; } // Encode authentication string $authstr = $cpuser.":".$cppass; $pass = base64_encode($authstr); $params = "dest=$ftpmode&email=$notifyemail&server=$ftphost&user=$ftpuser&pass=$ftppass&submit=Generate Backup"; // Make POST to cPanel fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n"); fputs($socket,"Host: $domain\r\n"); fputs($socket,"Authorization: Basic $pass\r\n"); fputs($socket,"Connection: Close\r\n"); fputs($socket,"\r\n"); // Grab response even if we don't do anything with it. while (!feof($socket)) { $response = fgets($socket,4096); if ($debug) echo $response; } fclose($socket); ?> PHP: Then create a cron job like this one: 15 1 * * * /usr/local/bin/php /home/yourcpaneluser/fullbackup.php Code (markup): This will make a full backup everyday and place it on an ftp server at 1:15 am.
that's a really neat script mnvlxxx, thanks for the share. also, just to let you know recep, hostgator automatically backs up your data on a weekly basis Finally, it's nice to see more and more turks are joining DP forums
I usually put the backups on a independant server but you can place them on home folder directory too. Basically the script makes the login in CPanel and then automatically submits the form on the selected page (in this case "/backup/dofullbackup.html"). I think most features of Cpanel can be used like that. Already tried it for automatic subdomain and database creation a works very well.
I couldn't get this script to work properly. It appears hostgator just made a few changes to what it wants on the form submission. Here are the few changes I made and now it appears to be working. I added an input for the ftp directory and edited the query string parameters to work. Posting the code just to hopefully save someone else time in the future. <?php // PHP script to allow periodic cPanel backups automatically, optionally to a remote FTP server. // This script contains passwords. KEEP ACCESS TO THIS FILE SECURE! (place it in your home dir, not /www/) // ********* THE FOLLOWING ITEMS NEED TO BE CONFIGURED ********* // Info required for cPanel access $cpuser = "user"; // Username used to login to CPanel $cppass = "pass"; // Password used to login to CPanel $domain = "domain"; // Domain name where CPanel is run $skin = "x3"; // Set to cPanel skin you use (script won't work if it doesn't match). Most people run the default x theme // Info required for FTP host $ftpuser = "user"; // Username for FTP account $ftppass = "pass"; // Password for FTP account $ftphost = "server"; // Full hostname or IP address for FTP host $ftpmode = "ftp"; // FTP mode ("ftp" for active, "passiveftp" for passive) $dir = "/"; // Directory to put the backup in // Notification information $notifyemail = "email"; // Email address to send results // Secure or non-secure mode $secure = 0; // Set to 1 for SSL (requires SSL support), otherwise will use standard HTTP // Set to 1 to have web page result appear in your cron log $debug = 0; // *********** NO CONFIGURATION ITEMS BELOW THIS LINE ********* if ($secure) { $url = "ssl://".$domain; $port = 2083; } else { $url = $domain; $port = 2082; } $socket = fsockopen($url,$port); if (!$socket) { echo "Failed to open socket connection… Bailing out!\n"; exit; } // Encode authentication string $authstr = $cpuser.":".$cppass; $pass = base64_encode($authstr); $params = urlencode("dest=" . $ftpmode . "&email_radio=1&email=" . $notifyemail . "&server=" . $ftphost . "&user=" . $ftpuser . "&pass=" . $ftppass . "&port=21&rdir=" . $dir . "&submit=Generate Backup"); // Make POST to cPanel fputs($socket,"POST /frontend/".$skin."/backup/dofullbackup.html?".$params." HTTP/1.0\r\n"); fputs($socket,"Host: $domain\r\n"); fputs($socket,"Authorization: Basic $pass\r\n"); fputs($socket,"Connection: Close\r\n"); fputs($socket,"\r\n"); // Grab response even if we don't do anything with it. while (!feof($socket)) { $response = fgets($socket,4096); if ($debug) echo $response; } fclose($socket); ?> Code (markup):
Anyone have another update on this? No longer works for hostgator it seems. Cron runs, but the address must not be working correctly because no backup is made.
You are not required to pay to your host for scheduling backup. You can simply create some script and schedule it. Please read this article for more information. http://www.hostliketoast.com/2011/0...ic-cpanel-backups-mysql-databases-files-cron/
You need to make sure the links are correct here, hostgator seems to change things up to prevent scripts like this from working. Although recently they were bought out by EIG; who knows what practices are in store now.
A script I wrote and used for db backup: easycronblog.blogspot.com/2011/11/php-to-backup-mysql-database.html