Cpanel panel automatically backs up Web site files using PHP _php tutorial

Source: Internet
Author: User
Tags cpanel cpanel login hosting
Cpanel Panel is a very powerful virtual hosting management panel, if you are a space quotient estimate this CP panel you are not unfamiliar oh, below I introduce the use of PHP implementation of automatic backup site files.

The code is as follows Copy Code
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 the This FILE secure!

The following items need to be set *********

cpanel Login Information
$cpuser = "* *"; cpanel Account
$cppass = "* * *"; cpanel Password
$domain = "* * *"; cpanel Domain name or IP
$skin = "X3"; The cpanel style that is being used, the default "x3".


/************** Backup Destination ***************
"Homedir"-Local home directory
"FTP"-Remote FTP backup (active mode)
"Passiveftp"-Remote FTP backup (passive mode)
"SCP"-encrypted transfer (requires server support)
****************************************/
$savedir = "ftp"; Backup destination, default "Homedir", that is, local backup only.

FTP uploaded information (backup destination is local, can not be filled in)

$ftpuser = "* * *"; FTP account
$ftppass = "***!"; FTP password
$ftphost = "* * *"; FTP Server IP
$ftpport = "21"; FTP port, default 21
$ftprdir = "/"; Remote FTP directory, default "/"

Notification information
$notifyemail = "* * @gmail. com"; Feedback Email Address

Safe Mode
$secure = 1; 0 is standard HTTP, 1 is SSL (requires host to support SSL)

A set value of 1 results in a page report 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= $notifyemail &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)) {


The above code copy is saved as: fullbackup.php file, uploaded to directory other than public_html

This global script contains cpanel login account and password, for security reasons, you need to put this script in a folder other than the Public_html folder, such as: "/home/yourname/backup", and set the permissions of the folder is 600. Remember!

2. Fill in the relevant information, modify the file name is fullbackup.php
3. Upload the above script to the "/home/yourdomain/beifen" directory. (No new Beifen directory can be created)
4. Change the permissions of the Beifen directory to 600
5. Open the clock daemon for the cpanel panel (Cron jobs).

Select the job frequency, and in the command bar, enter

The code is as follows Copy Code

1/usr/bin/php-q/home/yourname/backup/fullbackup.php

http://www.bkjia.com/PHPjc/633141.html www.bkjia.com true http://www.bkjia.com/PHPjc/633141.html techarticle cpanel Panel is a very powerful virtual hosting management panel, if you are a space quotient estimate this CP panel you are not unfamiliar oh, below I will introduce the use of PHP implementation of automatic backup site files ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.