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 cpanel full backup using PHP

Discussion in 'cPanel Developers' started by z-hoster, Oct 29, 2013.

  1. z-hoster

    z-hoster Member

    Joined:
    Aug 8, 2005
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Hey guys i have this code that works greate to create a full backup

    PHP:
    $xmlapi = new xmlapi($_CONFIG['server']['ip']);
    $xmlapi->password_auth($_CONFIG['server']['account'],$_CONFIG['server']['pass']);
    $xmlapi->set_port('2083');
        
    $api_args = array( 'ftp'$_CONFIG['server']['ip'], $_CONFIG['server']['account'], $_CONFIG['server']['pass'], $_SESSION['email'], 21'/public_html/wma/module/backup/files/' );
    $xmlapi->api1_query($_CONFIG['server']['account'],'Fileman','fullbackup',$api_args);
    Now i need to create a code to restor the file. I made a seach and found nothing on restoring a full backup using the xml-api.

    i know we can do it by command line using exec ....
    Code:
    # /scripts/restorepkg username
    But if there's any way of doing it with the cpanel API it would really make my day! Most of all PHP shell commands are blocked on my server for obvious reasons ... and i would really like it to remain blocked.
     
    #1 z-hoster, Oct 29, 2013
    Last edited: Oct 29, 2013
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Couple of notes:

    1. I really hope that /public_html/wma/modules/backup/files/ is locked down. It would be really bad to backup user files to a web accessible directory. A lot of backups contain databases which means you'd be potentially putting password hashes and credit card numbers out on the public web.

    2. It's likely a bad idea to restore backups from within user home directories. Once the backup is created, the user could modify it to change their account plan, privileges, etc. It's a lot safer to use system backups or /scripts/pkgacct and keep the backup archives out of the hands of users either in /home/cpmove-$user.tar.gz files or in a backup parition/directory using the built-in backup system.

    As far as restoring backups via API goes, you need to use the XML/JSON restoreaccount API call:

    RestoreAccount < SoftwareDevelopmentKit < TWiki

    I'd urge you to create backups using the Backup Configuration section of WHM, or with /scripts/pkgacct as it's inherently unsafe to trust anything provided to you from within a user's home directory.
     
  3. z-hoster

    z-hoster Member

    Joined:
    Aug 8, 2005
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for you help. I am doing this for a client that asked to have control on his backups from his administration panel. I got the directory secured with htaccess and i know i can trust the client.

    I took a look at the fonction you gave but it's not usable for what i want to do. Theres only 3 options in "type" (monthly, weekly, daily) In my case i would need to select something like "custom" and provide the full path to the backup file but thats not possible.

    I really hope using server commands is not the only way ... it would really sux to have to enable them.
    This is a script i found that does it using systeme()
    https://bitbucket.org/valroot/cpbackup/src/e2c4006e05e0/scripts/cpremote/cpremoterestor.php
     
    #3 z-hoster, Nov 1, 2013
    Last edited: Nov 1, 2013
Loading...

Share This Page