Copy accounts from a reseller WHM with out the root password (automatically)

I quickly wrote this script to easily run the backup process for all accounts of a reseller using WHM. This calls the backup process in cpanel for each account using the ftp/scp copy function. Once its done you need to manually restore accounts yourself in the folder you copied the accounts to.

An example to restore the account is something quick like

for i in *; do /scripts/restorepkg $i; done

Run the above command in the folder all the backup accounts were copied to.

The restore as well as the below script are best run in screen.

You need to manually create the domains file for the script below. You can do this by going to list accounts in WHM and at the bottom clicking the fetch csv option. Take all that data and create a file called domains on your server. Then run

cat domains | cut -d, -f1-3,10 | grep -v ^Domain, > domains2

This will format the file, calling in domains2 in a format the below script can use.

Script below, with instructions.


# Quick script to copy accounts from another cpanel server, with the reseller (not root password)
# This is just logging into cpanel to run the generate a full cpmove backup function in WHM

# Requires

## 1) logging into an account with the reseller password
## 2) the backup function working
## 3) getting the csv from list accounts and putting it in the right format

# Getting the csv

# Log into WHM as the reseller and go to list accounts. At the botton click 'Fetch CSV'
# Save it on the server you are copying it to, and call it 'domains'
# Run the below command
#cat domains | cut -d, -f1-3,10 | grep -v ^Domain, > domains2

# This is the WHM Password (resller pass)

# This is the WHM IP (server with the accounts now)

# This is the Remote FTP Username (ftp username)

# This is the remote FTP Password (ftp password)

# This is the remote FTP IP (ftp IP address where accounts are going to)

# This is the email address that gets notifications when the full backup is complete (your email address, the @ is %40)

# backup type, possibilities are
# ftp
# passiveftp
# scp

# Port your ftp or scp port

# remote dir, default is %2F which is blank
# for scp follow format of %2Fhome%2Fusername for /home/username

# Sleep time in seconds (setting this too low could cause may backup processes to run at once)

# you don't need to run this as root, but you may need to define a HOME
export HOME=/root

if [ ! -f domains2 ]; then
 echo 'Domains file missing';
# there is no error checking, so double check the above

for i in $(cat domains2 | cut -d\, -f3); do
 THEME=`cat domains2 | grep ,$i, | cut -d, -f4 | grep -v ^#`;
 curl -u $i:$HTTPPASS -k "https://$SERVER:2083/frontend/$THEME/backup/dofullbackup.html?dest=$TYPE&email=$MYEMAIL&server=$FTPSERVER&user=$FTPUSER&pass=$FTPPASS&port=$PORT&rdir=$REMOTEDIR"
 echo "Finished $i, Sleeping"
 sleep $sleep

Leave a Reply

Your email address will not be published. Required fields are marked *