Restoring cpanel full backup using PHP


Aug 8, 2005
Hey guys i have this code that works greate to create a full backup

$xmlapi = new xmlapi($_CONFIG['server']['ip']);
$api_args = array( 'ftp', $_CONFIG['server']['ip'], $_CONFIG['server']['account'], $_CONFIG['server']['pass'], $_SESSION['email'], 21, '/public_html/wma/module/backup/files/' );
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 ....
# /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.
Last edited:


Well-Known Member
Verifed Vendor
Jun 17, 2010
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.


Aug 8, 2005
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()
Last edited: