Backups/Restore and Migration Calls

raonaveed

Member
Nov 30, 2009
13
0
51
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
 

leefrom

Active Member
May 27, 2008
30
0
56
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...
 

raonaveed

Member
Nov 30, 2009
13
0
51
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
 

leefrom

Active Member
May 27, 2008
30
0
56
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.
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
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.
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
 

Spiral

BANNED
Jun 24, 2005
2,018
8
193
(Last post above assuming server owner didn't disable reseller to user logins)
 

raonaveed

Member
Nov 30, 2009
13
0
51
:) 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.
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
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
 

raonaveed

Member
Nov 30, 2009
13
0
51
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
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?
 

raonaveed

Member
Nov 30, 2009
13
0
51
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 = '[email protected]';

//
// 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);
}
?>
 

Infopro

Well-Known Member
May 20, 2003
17,085
521
613
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.
 

MACscr

Well-Known Member
Sep 30, 2003
198
5
168
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?
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
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
 

MACscr

Well-Known Member
Sep 30, 2003
198
5
168
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
Ah, wrong keyword. Thanks!
 

MACscr

Well-Known Member
Sep 30, 2003
198
5
168
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?
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
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