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.

Backups/Restore and Migration Calls

Discussion in 'cPanel Developers' started by raonaveed, May 9, 2010.

  1. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Hello!

    This is development question can i do the followings.

    1. Can i generate all accounts backups of my customer using his reseller login of old host? in this case i have the root login of myserver so no issue for me to run any ssh command at my server but point is this does is it possible for me to do that without mentioned all accounts list or password etc or SSH access of his old host?... Its kind of same feature that you allow for one account migration in WHM for root called (Copy an account from another server with account password).

    2. How i can restore multiple accounts using SSH command or xml-api calls i want to allow my customers to restore multiple accounts by themselves so which means reseller will do themselves.

    3. How i can make an efficenet plugin which check server load first before taking or restoring backup how to check server load ? so i get a numeric value and on the bases of i allow or apply specific command?

    4. What Api call to restore single account?


    Looking for great help same as before.
    Thanks
    Rao
     
  2. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    Unfortunately, it looks like most of the backup functionality has not been exposed to the API at this time.

    However, you can restore a backup at the command line by placing it in /home and doing:

    /scripts/restorepkg <username>

    So you can automate that.

    Also, the cpanel backup system does already check the load specified in WHM | Tweak Settings | The load average above the number of CPUs at which log file processing should be suspended.

    If you have that set to 0, it will wait until the load is .99 or lower to run (or continue running).

    Hope that helps...
     
  3. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    ok great thanks for clearing i have some other questions

    1. Is it possible to fetch account from anyother server without having root login or that server? i mean if i have only my cpanel account details how i can fetch that account using php code or ssh command to a new server where i have the SSH as well as root access?

    2. How i can generate backups using php or SSH commands and send them to an ftp server auto like how cpanel backup feature work

    Thanks
     
  4. leefrom

    leefrom Active Member

    Joined:
    May 27, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    6
    I'm afraid I'm not aware of a built in way to do those two things. You'd need to scrape or use Expect to automate those processes.
     
  5. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    Actually you can do it from the interface if you have the reseller login but it's not pretty ....

    You can use the reseller account to login to the cpanel control panels of each of the resold accounts without password and setup "on demand" full backups with remote FTP as the storage destination.

    Without either root or reseller access then yes ---

    would need to login using the password to each and every cpanel account
     
  6. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    (Last post above assuming server owner didn't disable reseller to user logins)
     
  7. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    :) well thanks everyone though i was looking something from cpanel team as they know as they coded it, anyway finaly i have done what i was looking with combination of PHP and SSH commands. so Thanks for all.
     
  8. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Alright, so let's start from the beginning:

    1) it is possible to generate a backup with just a user's login. You call the API1 function Fileman::fullbackup via the XML-API

    ApiFileman < ApiDocs/Api1 < TWiki

    Once this has been done, call Backups::listfullbackups to monitor for the creation of the new file

    ApiBackups < ApiDocs/Api2 < TWiki

    This can be downloaded via the instructions in the API docs (you should be able to do this with reseller login, however your milage may vary).

    2.) inside of 11.25.1 we have added a new call called "backuprestore" that will allow you to restore backups, this can be used to automate the restoration process. That being said, /scripts/restorepkg is probably preferable.

    3.) You can generate backups via the CLI using SSH via /scripts/pkgacct $accountname. This will only work as root
     
  9. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Hello!

    Thanks this is what i was looking but could you clear followings

    1. Fileman::fullbackup( dest, server, user, pass, email, port, rdir )
    how should i run the above code in php? i mean if i have a root or reseller login details than how i will call that function and how the system will know i am asking backup for which account?

    Like how i tell system for which account i am trying to generate backup using that function command line?
     
  10. raonaveed

    raonaveed Member

    Joined:
    Nov 30, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    HellO!

    below is code which i was looking

    <?php
    $target_host = 'DomainToBackup.com';
    $cpanel_userid = 'yourCpanelUsername';
    $cpanel_pass = 'yourCpanelPassword';
    $cpanel_theme = 'yourCpanelTheme';
    $ftp_host = 'ftp.storageDomain.com';
    $ftp_user = 'ftp_host_Username';
    $ftp_pass = 'ftp_host_Password';
    $email = 'your@email.com';

    //
    // DO NOT ALTER ANYTHING BELOW THIS LINE
    //
    $user_pass = "$cpanel_userid:$cpanel_pass";
    $authentication = base64_encode($user_pass);
    $socket = fsockopen($target_host,2082);
    if (!$socket) {
    echo "$errstr ($errno)<br />\n";
    } else {
    fputs($socket,"POST /frontend/$cpanel_theme/backup/dofullbackup.html?dest=ftp&email=$email&server=$ftp_host&user=$ftp_user&pass=$ftp_pass&submit=Generate Backup\r\n");
    fputs($socket,"HTTP/1.0\r\n");
    fputs($socket,"Host: $target_host\r\n");
    fputs($socket,"Authorization: Basic $authentication \r\n");
    fputs($socket,"Connection: close\r\n\r\n");

    while (!feof($socket)) {
    $request = fgets($socket, 4096);
    }
    echo 'Done.';
    fclose($socket);
    }
    ?>
     
  11. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,456
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Important cPanel/WHM Version Number Designation Change

    Please Note: Important cPanel/WHM Version Number Designation Change

    As of July 28, 2010 the cPanel/WHM version number designations have been officially changed.

    Version 11.25.1 is now designated 11.28 and version 11.25.2 is now designated 11.30.

    These new changes were explained in some detail recently at the July 2010 - Quarterly Road map - Webinar direct from cPanel's PodCast Studio in Houston, Texas with speakers David Grega and Mario Rodriguez.

    An official press release about these changes is forthcoming and can be accessed at this link as soon as it's made available to the Forum Team:
    Important cPanel/WHM Version Number Designation Change (To be updated)

    This post serves to update users who are subscribed to threads (where this message is posted) looking forward to upcoming enhancements in future versions of cPanel.
     
  12. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Maybe Im blind, but im not seeing this backup restore feature that you mentioned called 'backuprestore'. Its no where in your docs for any version of the api. Am I missing something?
     
  13. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi MACscr,

    I think this is what Matt is referring to: RestoreAccount < SoftwareDevelopmentKit < TWiki. The XML/JSON-API function is 'restoreaccount' and is officially available in 11.28+ (though is probably present in some other incarnation of the development builds since 11.25 [like 11.25.1, which Matt references, and 11.27]).

    Regards,
    -DavidN
     
  14. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Ah, wrong keyword. Thanks!
     
  15. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    No problem. Glad I could help!

    Best Regards,
    -DavidN
     
  16. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    DavidN,

    Is there really no way to specify the path to the file that needs to be restored? I am trying to write a script for doing migrations from servers that do not have root access and have multiple accounts to restore. Also, with the RestoreAccount api function, do resellers have access to it?
     
  17. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    I'm fairly certain that only root or a reseller with 'all root' access can exercise that remote API call. An average, "can create accounts", reseller is not privileged enough. This coincides with how WHM's "Main >> Backup >> Restore Backups" works (which I'm certain requires 'all root' privs). And, like that function, it is designed to specifically work with the centralized backups generated by WHM's "Main >> Backup >> Configure Backup". It's really not for migration purposes, despite the backup file architecture being nearly identical.

    I'm not sure what the best course of action is for you. I guess the long way (and maybe the only way at this time) would be to create a custom API2 module that the reseller can invoke which utilizes privilege escalation. But even then, if there isn't a privileged user (or some sort of trusted,surrogate root) on the destination server...you're kinda sunk.

    Unfortunately, until cPanel comes out with a migration/package/restore API, it's going to be difficult for you to provide the function to your customers that you desire...at least without a significate amount of code and security implications.

    Sorry I can't be more help,
    -DavidN
     
Loading...

Share This Page