I was looking for a working script to take full backup (all files+databases+emails) manually or using cron services on my hosting server, each CPanel user by one. But most of the scripts are either old, totally unusable or commercial.
So I wrote one for my own use and sharing here so others don’t need to re-invent the wheel
01 | <!--?php |
02 | // Must include cPanel API |
03 | include "xmlapi.php" ; |
04 | |
05 | //CONFIG SECTION |
06 | //******************************************************* |
07 | // Credentials for cPanel account |
08 | $source_server_ip = "your_domain_or_IP" ; // Server IP or domain name eg: 212.122.3.77 or cpanel.domain.tld |
09 | $cpanel_account = "userid" ; // cPanel username |
10 | $cpanel_password = "password" ; // cPanel password |
11 | // Credentials for FTP remote site |
12 | $ftphost = "ip_or_hostname_of_ftp" ; // FTP host IP or domain name |
13 | $ftpacct = "userid" ; // FTP account |
14 | $ftppass = "password" ; // FTP password |
15 | $logs_dir = "/" ; //FTP Remote Folder |
16 | $email_notify = 'your_email@domain.com' ; // Email address for backup notification |
17 | $backupexpireindays =21; //3 weeks expire time in days, 21 days = 7*24*60 |
18 | //END OF CONFIG SECTION |
19 | //******************************************************* |
20 | //Do not edit below this line |
21 |
22 | $backupexpireindays =( $backupexpireindays *24)*3600; //convert it to seconds, 24 hours * 60 minutes * 60 seconds |
23 |
24 | $xmlapi = new xmlapi( $source_server_ip ); |
25 | $xmlapi --->password_auth( $cpanel_account , $cpanel_password ); |
26 | $xmlapi ->set_port( '2083' ); |
27 | |
28 | // Delete any other backup with filetime greater than expire time, before create new backup |
29 | $conn_id = ftp_connect( $ftphost ); |
30 | $login_result = ftp_login( $conn_id , $ftpacct , $ftppass ); |
31 |
32 | ftp_chdir( $conn_id , $logs_dir ); |
33 | $files = ftp_nlist( $conn_id , "." ); |
34 | foreach ( $files as $filename ) { |
35 | $fileCreationTime = ftp_mdtm( $conn_id , $filename ); |
36 | //$date = date("F j, Y, g:i a", ftp_mdtm($conn_id, $filename)); |
37 | //print "<br>Timestamp of '$filename': $date"; |
38 | $fileAge =time(); |
39 | $fileAge = $fileAge - $fileCreationTime ; |
40 | if ( $fileAge > $backupexpireindays ) { // Is the file older than the given time span? |
41 | //echo "<br>The file $filename is older than Expire time :$expiretime ...Deleting\n"; |
42 | ftp_delete( $conn_id , $filename ); |
43 | //echo "<br>Deleted<br><br>"; |
44 | } |
45 | } |
46 |
47 | ftp_close( $conn_id ); |
48 | |
49 | $api_args = array ( |
50 | 'passiveftp' , |
51 | $ftphost , |
52 | $ftpacct , |
53 | $ftppass , |
54 | $email_notify , |
55 | 21, |
56 | '/' |
57 | ); |
58 | |
59 | $xmlapi ->set_output( 'json' ); |
60 | print $xmlapi ->api1_query( $cpanel_account , 'Fileman' , 'fullbackup' , $api_args ); |
61 | |
62 | ?> |
You need to save it with .php extension (upload it to your server) and download include file from xmlapi.zip(right click->save as) and extract it to the same folder (on your web server). Create cron job from your CPanel or trigger it manually to get full backup in your FTP server, That’s it.
OR
You can fork from my git hub Repositories at cpanel-Fullbackup
Enjoy