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.

Restoring user generated full cPanel backup on 11.44 on WHM?

Discussion in 'Data Protection' started by jrianto, Jul 7, 2014.

  1. jrianto

    jrianto Active Member

    Joined:
    Jun 9, 2008
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    I am having problems restoring a user generated full cPanel backup file on WHM 11.44.

    I am trying to run a restore of a full cPanel backup file stored on the /home folder.

    Upon initiating the restore with curl, it does not execute. Apparently now the restore function are triggering a series of javascript calls that requires an actual browser with JS functionality to actually process the restoration.

    This breaks automation scripts that uses curl to initiate restore process through WHM.

    Is there a workaround for this, maybe using an API, so that during restoration process, it is not required for a JS enabled browser to actually having to wait with the browser window open until the restore process completes?

    The only workaround I have right now is using phantomjs and casperjs, but it would be great if the solution is right out of the box from WHM.

    Can you please give me a pointer of a better workaround to accomplish this?
     
  2. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    Will

    Code:
    /scripts/restorepkg /home/XXXXX
    
    work for you?

    ------------

    The transfer system now provides API access in 11.44, however thats only for transferring from a remote machine.

    https://documentation.cpanel.net/di...tion+Calls+-+Transfer+and+Restore+Walkthrough

    We currently don't have an exposed API for 'AccountLocal' session which is what you would need to call this from the API.

    From Whostmgr::Transfers::Session::Config:
    Code:
    our %ITEMTYPE_NAMES = (
        1000 => 'FeatureListRemoteRoot',   # accessible via create_remote_user_transfer_session api
        2000 => 'PackageRemoteRoot',       # accessible via create_remote_root_transfer_session api
        3000 => 'AccountRemoteRoot',        # accessible via create_remote_root_transfer_session api
        4000 => 'AccountRemoteUser',        # accessible via create_remote_user_transfer_session api
    [B]    5000 => 'AccountLocal',                  # Only accessible via WHM UI
    [/B]    6000 => 'LegacyAccountBackup',      # Only accessible via WHM UI
        7000 => 'AccountUpload',               # Only accessible via WHM UI
    );
    
    If /scripts/retorepkg isn't going to work for you, and need an API called to access AccountLocal, please open a feature request at cPanel Feature Requests

    You could also manually create the session type you need in the mean time (however this uses internal APIs so it may break in the future)

    Code:
            my $session_obj = _setup_session_obj(
                { 'initiator' => 'quickrestore', 'create' => 1, 'session_id_template' => $host },                                                                                                                                   
                {    
                    'session' => { 
                        'scriptdir'    => '/scripts',
                        'state'        => 'preflight',
                        'session_type' => $Whostmgr::Transfers::Session::SESSION_TYPES{'Local'} ,
                    },   
                    'queue'   => { 'RESTORE' => 0 }, 
                    'options' => { 
                        'unrestricted' => $unrestricted_restore,
                    }    
                }    
            );   
        
            my $id = $session_obj->id();
    
    Then you could call the enqueue API, and the start_transfer API. See the below code as an example of what you need to pass to the enqueue API:

    Code:
            $session_obj->enqueue(
                'AccountLocal',
                {    
                    'ip'                          => $ip, 
                    'force'                       => ( $force ? 1 : 0 ), 
                    'user'                        => $username,
                    'localuser'                   => $username,
                    'skipres'                     => ( $skiprestorereseller ? 1 : 0 ), 
                    'customip'                    => $custom_ip,
                    'cpmovefile'                  => $filepath,
                    'replaceip'                   => $replaceip,
                    'skipaccount'                 => ( ( $force && Cpanel::AcctUtils::accountexists($username) ) ? 1 : 0 ), 
                    'overwrite_sameowner_dbusers' => 1,
                    'overwrite_sameowner_dbs'     => 1,
                },   
                $Whostmgr::Transfers::Session::QUEUE_STATES{'RESTORE_PENDING'}
            );   
    
     
  3. jrianto

    jrianto Active Member

    Joined:
    Jun 9, 2008
    Messages:
    44
    Likes Received:
    0
    Trophy Points:
    6
    Thank you for pointing it out Nick. Yes I am using the /scripts/restorepkg right now, it works.

    The only down side is that I need to add a cron job to detect if there is any new restore requests, if so, then the restore is triggered.

    That would be fine I suppose rather than making it more complex which a potential of breaking in the future.

    Thanks again, really appreciate the insights.
     
Loading...

Share This Page