Backing up accounts (hacky way)

Deehem

Member
PartnerNOC
Jul 6, 2006
18
0
151
Preston, UK
cPanel Access Level
DataCenter Provider
Hi All,

I was wondering if anybody else had experience with using APIv1 (I know, I know) to back up accounts via FTP?

I'm trying to perform a HTTP request to the server to do so with the cPanel account credentials. Here is what I have:

Code:
https://server.hostname.net:2083/json-api/cpanel
?cpanel_jsonapi_module=Fileman
&cpanel_jsonapi_func=fullbackup
&cpanel_jsonapi_apiversion=1
&dest=ftp
&server=11.22.11.22
&user=USERNAME
&pass=PASSWORD
&[email protected]
&port=21
&rdir=/
This generates the backup to the homedir successfully, however doesn't even attempt to communicate with the FTP server. Firewalls are disabled on both servers for sanity sake, and entering the above details in to the generate full backup system to transfer over FTP works absolutely fine, it's just this API call that doesn't work.

This is on 11.40.13.

I am out of ideas personally.
 

jasonhk

Well-Known Member
Nov 11, 2005
48
0
156
I've got this working using the cPanel XMLAPI Client Class here:
https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php

PHP:
include "xmlapi.php";
	// Instantiate object
		$xmlapi = new xmlapi($ip);
		// Set to use secure cPanel port
		//  you will have to alter this to 2082 if your PHP doesn't have SSL support enabled
		$xmlapi->set_port('2083');
		 // Set cPanel credentials
		$xmlapi->password_auth($cp_user, $cp_pass);
		// Uncommentfor debugging
		$xmlapi->set_debug(1);
		// Setup an ordinal array with arguments in proper order
		$args = array(
		    'ftp',                  // Destination type
		    $remote_server,         // Remote destination address/domain
		    $remote_user,           // Destination's FTP user login
		    $remote_pass,           // Destination's FTP password login
		    $confirm_email_addy,    // Email address to send notification
		    $remote_port,           // Listening FTP port on remote destination
		    $remote_dir,            // Directory to store backup on remote destination
		);

		// Make API1 query
		echo "<br>Connecting to cPanel API at $ip and initating transfer for username: $cp_user <br>";
		$results = $xmlapi->api1_query($cp_user, 'Fileman', 'fullbackup', $args);
		print_r($results);
 

Deehem

Member
PartnerNOC
Jul 6, 2006
18
0
151
Preston, UK
cPanel Access Level
DataCenter Provider
Thanks. I'm using something similar which is the Perl cPanel::PublicAPI module with no luck. It sends the request, but then just refuses to FTP from there and doesn't even send a completion email :(

As there are no logs for the end-user backup process, this can't be easily debugged. Quite frustrating.
 

Deehem

Member
PartnerNOC
Jul 6, 2006
18
0
151
Preston, UK
cPanel Access Level
DataCenter Provider
Thanks for the suggestions.

I opted to use the cPanel::PublicAPI Perl module for this. I have attached the full working script below in a gist, for reference.

/https://gist.github.com/Deehem/6dd15d79775730e64b34
 

robnelli

Member
Apr 16, 2004
14
0
151
I tried your script method using the cPanel::PublicAPI Perl module but got a 403 Forbidden Access response. Any idea what it was that was denied and how to fix it?
Code:
debug: Using user param from object creation
debug: Using pass param from object creation
debug: loaded serializer: JSON::Syck
debug: api_request: ( cPanel::PublicAPI=HASH(0x15f8f80), cpanel, /xml-api/cpanel, POST, HASH(0x15f8ef0),  )
debug: failed to load encoder: cPanel/CPAN/URI/Escape.pm
debug: loaded encoder: URI/Escape.pm
debug: Found port for service cpanel to be 2082 (usessl=0)
debug: POST /xml-api/cpanel HTTP/1.1
Host: http://www.domain.net
Connection: Close
Content-Length: 238
User-Agent: cPanel::PublicAPI (perl) 1.002
Authorization: Basic anJuaG9zdGk6bGVlbmllLTE=

[email protected] domain.net&cpanel_xmlapi_module=Fileman&cpanel_xmlapi_cpanel_xmlapi_user=&arg-0=ftp&arg-3=
xxxxxxxx&cpanel_xmlapi_apiversion=1&arg-1=nj01.domain.com&arg-6=%252F&arg-2=supersof&arg-5=21&cpanel_xmla
pi_func=fullbackup
debug: HTTP LINE[HTTP/1.1 403 Forbidden Access denied
]
debug: HEADER[content-type]=[text/xml]
debug: HEADER[connection]=[close]
debug: HEADER[server]=[cpsrvd/11.42.1.13]
debug: READ TYPE=close
Server Error from domain.net: HTTP/1.1 403 Forbidden Access denied
 
Last edited:

caylean

Active Member
Jul 2, 2013
27
0
1
cPanel Access Level
Root Administrator
I opted to use the cPanel::PublicAPI Perl module for this.
Hello Daahem,
I ran into a problem too, maybe I have missed something...
Can't locate cPanel/PublicAPI.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /home/ACCOUNTNAME/public_html/backup/backup.pl line 3.
BEGIN failed--compilation aborted at /home/ACCOUNTNAME/public_html/backup/backup.pl line 3.
Where can i find that Public Api? Had searched in cPanel for it, but nothing was to be found.

Kind Regards
 

John connor

Registered
Feb 5, 2015
3
0
1
cPanel Access Level
Website Owner
I have no idea how to run Perl. I have a Perl Module Installer in cPanel. How do I do this? Do I place the cpanel_backup.pl in th ePerl folder of the directory in FTP? Do I run a cron job? How do I install the Public API?

- - - Updated - - -

I should mention that I'm on a shared account, not a VPS so it looks like I have to run commands and I don't think I can do that.
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,910
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
I have no idea how to run Perl. I have a Perl Module Installer in cPanel. How do I do this? Do I place the cpanel_backup.pl in th ePerl folder of the directory in FTP? Do I run a cron job? How do I install the Public API?

- - - Updated - - -

I should mention that I'm on a shared account, not a VPS so it looks like I have to run commands and I don't think I can do that.
You can upload the custom Perl script to your account's home directory and utilize the path to it when setting up a cron job. The "Perl Modules" option in cPanel should allow you to install the "cPanel: PublicAPI" Perl module. Note that this is an unsupported user-submitted backup script, so it's not something we can support.

Thank you.
 

mimin

Registered
Jul 7, 2015
2
0
1
Indonesia
cPanel Access Level
Root Administrator
You can upload the custom Perl script to your account's home directory and utilize the path to it when setting up a cron job. The "Perl Modules" option in cPanel should allow you to install the "cPanel::publicAPI" Perl module. Note that this is an unsupported user-submitted backup script, so it's not something we can support.

Thank you.
Michael, what is the best choices for you if you need something like what OP asked ?
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,910
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Michael, what is the best choices for you if you need something like what OP asked ?
The main purpose of the custom script is to allow cPanel users the ability to automatically backup accounts on a daily basis. If you are asking for the best supported option, it would be to obtain a VPS or dedicated server so you can configure backups as "root" using the supported options provided by cPanel.

Thank you.