How to set up automatic backups
- Category : cPanel Question
- Posted on : Jan 01, 2020
- Views : 1,359
- By : HostSEO
Using the script provided below you will be able to make automatic full cPanel backups of your account.
This backup script includes SSL support. This is not necessary if you run the script on the server for which you are generating the backup, but the SSL support could be important if you are running the script somewhere else to connect to your cPanel hosting account.
<?php $cpaneluser = 'user'; // cPanel username $cpaneluserpass = 'pass'; // cPanel password. Please note that the cPanel password should not contain special symbols like '&^' to avoid the interruption of the script work $theme = 'paper_lantern'; // Must match current selected cPanel theme ('paper_lantern' in the majority of cases, 'x3' is possible as well) $ftp = true; // Needs to be enabled for the backup to be uploaded to your Namecheap or third-party server; do NOT change the value $ftpserver = 'serverX.web-hosting.com'; // Must be 'localhost' for current server or custom hostname for remote FTP upload $ftpusername = 'user'; // cPanel/SFTP username. Should be the same as cPanel username for local upload or custom for remote upload $ftppassword = 'pass'; // cPanel/SFTP password. Should be the same as cPanel password for local upload or custom for remote upload $ftpport = '21098'; // SFTP port. Should be 21 in most cases. $ftpdirectory = '/home/'.$cpaneluser.'/backups'; // Directory on FTP server to store backups. MUST EXIST BEFORE BACKUP OR BACKUP PROCESS WILL FAIL. Also, make sure ot update the 'cpaneluser' part with your current cPanel username. // Do not edit below this line $domain = 'localhost'; $secure = true; $auth = base64_encode($cpaneluser . ":" . $cpaneluserpass); if ($secure) { $url = "ssl://" . $domain; $port = 2083; } else { $url = $domain; $port = 2082; } $socket = fsockopen('localhost', 2082); if (!$socket) { exit("Failed to open socket connection."); } if ($ftp) { $params = "dest=scp&server=$ftpserver&user=$ftpusername&pass=$ftppassword&port=$ftpport&rdir=$ftpdirectory&submit=Generate Backup"; } else { $params = "submit=Generate Backup"; } fputs($socket, "POST /frontend/" . $theme . "/backup/dofullbackup.html?" . $params . " HTTP/1.0\r\n"); fputs($socket, "Host: $domain\r\n"); fputs($socket, "Authorization: Basic $auth\r\n"); fputs($socket, "Connection: Close\r\n"); fputs($socket, "\r\n"); while (!feof($socket)) { $response = fgets($socket, 4096); // echo $response; //uncomment this line for debugging } fclose($socket);?>
NOTE: Make sure to replace cPanel user and password with your own details.
To schedule the script to run regularly, save it as fullbackup.php in your home directory and add a new cron job with the following syntax:
00 2 * * 1 /usr/local/bin/php /home/youraccount/fullbackup.php (Runs every Monday night at 2:00 a.m.)
In order to exclude the backups folder from automatic backup generation (if your account is a couple GBs big, disk space usage will increase drastically, as every new backup will contain all the former ones), look for the cpbackup-exclude.conf file in the home directory, add the folder name and use an asterisk * after the directory if you want to exclude all the files from a directory, or add the path to the file you wish to exclude from backups then and save the changes.
NOTE: If there is no cpbackup-exclude.conf file in the home directory, you need to create one manually.
NOTES:
- If your account is hosted on a shared server, make sure that your script usage is optimized in order not to overload the server.
- We do not provide code debugging services. This script is provided as a matter of courtesy for your convenience only.
If you have Premium or Business Hosting, it is possible to manage full cPanel backups using the AutoBackup cPanel plugin.
Categories
- cPanel Question 47
- cPanel Software Management 29
- cPanel Tutorials 13
- Development 29
- Domain 13
- General 19
- Linux Helpline (Easy Guide) 156
- Marketing 47
- MySQL Question 13
- News 2
- PHP Configuration 14
- SEO 4
- SEO 42
- Server Administration 84
- SSL Installation 54
- Tips and Tricks 24
- VPS 3
- Web Hosting 44
- Website Security 22
- WHM questions 13
- WordPress 148
Subscribe Now
10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!Archive Calendar
Sat | Sun | Mon | Tue | Wed | Thu | Fri |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Recent Articles
-
Posted on : Sep 17
-
Posted on : Sep 10
-
Posted on : Aug 04
-
Posted on : Apr 01
Tags
- ts
- myisam
- vpn
- sql
- process
- kill
- tweak
- server load
- attack
- ddos mitigation
- Knowledge
- layer 7
- ddos
- webmail
- DMARC
- Development
- nginx
- seo vpn
- Hosting Security
- wireguard
- innodb
- exim
- smtp relay
- smtp
- VPS Hosting
- cpulimit
- Plesk
- Comparison
- cpu
- encryption
- WHM
- xampp
- sysstat
- optimize
- cheap vpn
- php-fpm
- mariadb
- apache
- Small Business
- Error
- Networking
- VPS
- SSD Hosting
- Link Building
- centos
- DNS
- optimization
- ubuntu