The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Backing up accounts (hacky way)

Discussion in 'cPanel Developers' started by Deehem, May 2, 2014.

  1. Deehem

    Deehem Member
    PartnerNOC

    Joined:
    Jul 6, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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=email@address.com
    &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.
     
  2. jasonhk

    jasonhk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    6
    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);
     
  3. Deehem

    Deehem Member
    PartnerNOC

    Joined:
    Jul 6, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,696
    Likes Received:
    656
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  5. Deehem

    Deehem Member
    PartnerNOC

    Joined:
    Jul 6, 2006
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  6. robnelli

    robnelli Member

    Joined:
    Apr 16, 2004
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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=
    
    arg-4=user@ 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
     
    #6 robnelli, May 14, 2014
    Last edited: May 14, 2014
  7. caylean

    caylean Member

    Joined:
    Jul 2, 2013
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello Daahem,
    I ran into a problem too, maybe I have missed something...
    Where can i find that Public Api? Had searched in cPanel for it, but nothing was to be found.

    Kind Regards
     
  8. John connor

    John connor Registered

    Joined:
    Feb 5, 2015
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    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.
     
  9. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,696
    Likes Received:
    656
    Trophy Points:
    113
    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.
     
  10. mimin

    mimin Registered

    Joined:
    Jul 7, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Indonesia
    cPanel Access Level:
    Root Administrator
    Michael, what is the best choices for you if you need something like what OP asked ?
     
  11. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,696
    Likes Received:
    656
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page