The CPanel panel uses php to automatically back up website files. CPanel panel is a very powerful virtual host Management Panel. if you are a space provider, you are not familiar with this cp panel, the following describes how to use php to automatically back up website files. the CPanel panel is a very powerful virtual host Management Panel. if you are a space provider, it is estimated that you are familiar with this cp panel, the following describes how to use php to automatically back up website files.
The code is as follows: |
|
// PHP script to allow periodic cPanel backups automatically. // Based on script posted by max. hedroom in cpanel.net forums // This script contains passwords. keep access to this file secure! // ********** The following items need to be set ********* // CPanel logon information $ Cpuser = "**"; // CPanel account $ Cppass = "***"; // CPanel password $ Domain = "***"; // The domain name or IP address of cPanel $ Skin = "x3"; // cPanel style in use. the default value is "x3 ". /*************** Backup destination *************** "Homedir"-local main directory "Ftp"-remote FTP backup (active mode) "Passiveftp"-remote FTP backup (passive mode) "Scp"-encrypted transmission (server support required) ****************************************/ $ Savedir = "ftp"; // backup destination. the default value is "homedir", that is, only local backup is performed. // FTP-uploaded information (the backup destination is local, which can be left blank) $ Ftpuser = "***"; // FTP account $ Ftppass = "***! "; // FTP password $ Ftphost = "***"; // FTP server IP address $ Ftpport = "21"; // FTP port, default: 21 $ Ftprdir = "/"; // remote FTP directory, default "/" // Notification information $ Notifyemail = "** @ gmail.com"; // email address for feedback // Security mode $ Secure = 1; // 0 is standard http, and 1 is ssl (the host must support ssl) // When the value is set to 1, a webpage report will be generated in the schedule record. $ Debug = 0; // Do not change the following content! ********* 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 = $ savedir & email = $ paiyemail & server = $ ftphost & user = $ ftpuser & pass = $ ftppass & port = $ ftpport & rdir = $ ftprdir & submit = Generate Backup "; // Make POST to cPanel Fputs ($ socket, "POST/frontend/". $ skin. "/backup/dofullbackup.html? ". $ Params." HTTP/1.0rn "); Fputs ($ socket, "Host: $ domainrn "); Fputs ($ socket, "Authorization: Basic $ passrn "); Fputs ($ socket, "Connection: Closern "); Fputs ($ socket, "rn "); // Grab response even if we don't do anything with it. While (! Feof ($ socket )){ |
Copy and save the preceding code as the fullbackup. php file and upload it to a directory other than public_html.
This global script contains the logon account and password of cPanel. to ensure security, you need to put this script in a folder other than the public_html folder, for example, "/home/yourname/backup ", and set the folder permission to 600. Remember!
2. fill in the relevant information and change the file name to fullbackup. php.
3. Upload the above script to the "/home/yourdomain/beifen" directory. (No beifen directory can be created)
4. change the beifen directory permission to 600.
5. open the clock daemon job (Cron Jobs) on the cpanel panel ).
Select the job frequency and enter it in the command column.
The code is as follows: |
|
1/usr/bin/php-q/home/yourname/backup/fullbackup. php |
...