How to Migrate cPanel Account: Single Account and Bulk Transfer via Terminal

Migrating cPanel accounts between servers is a routine task for administrators seeking to optimize server resources or enhance performance. This guide provides a concise walkthrough of migrating both a single cPanel account and all cPanel accounts to a new server using the terminal.

Migrating a Single cPanel Account:

Step 1: Connect to Source Server

ssh your_username@your_server_ip

Step 2: Create Full Backup of this cPanel Account

cd /home/
/scripts/pkgacct [cpanel_username]

Step 3: Transfer Backup to Destination Server
now, we need to transfer this cPanel account from our old server to the new one.

rsync -av --progress /home/cpmove-[cpanel_username].tar.gz root@103.193.72.49:/home

where 103.193.72.49 is your new server IP. Now, all the file in this cPanel is transferring to our new server!

Step 4: Restore Backup

Connect to Destination Server

ssh your_username@your_server_ip

Finally, in our new server, fire the following command,

/scripts/restorepkg cpmove-[cpanel_username].tar.gz

Check the new server to ensure successful migration.

Migrating All cPanel Accounts:

Step 1: Generate All cPanel Accounts List on Source Server

ls /var/cpanel/users | while read a; do
/scripts/pkgacct $a
done

Step 2: Transfer the List to Destination Server

rsync -av --progress /home/*.tar.gz root@103.193.72.49:/home

where 103.193.72.49 is your new server. Now, all the files are transferring to our new server!

Step 3: Restore Backup

Connect to Destination Server

ssh your_username@your_server_ip

Finally, in our new server, fire the following command,

ls /home/ | awk -F'[-.]' '{print $2}' | while read a; do
/scripts/killacct --user=$a
/scripts/restorepkg $a
done

Check the new server to ensure all cPanel accounts have been successfully migrated.

 

Migrating Multiple cPanel Accounts at a time:

Step 1: Generate Multiple cPanel Accounts on Source Server

#!/bin/bash

# List of cPanel accounts to create backups
accounts=("account1" "account2" "account3")

for account in "${accounts[@]}"; do
    /scripts/pkgacct $account
done

In here, “account1” “account2” “account3” “account4” “account5” “account6” ……. should replace with cPanel usernames

Step 2: Transfer the List to Destination Server

rsync -av --progress /home/*.tar.gz root@103.193.72.49:/home

where 103.193.72.49 is your new server. Now, all the files are transferring to our new server!

Step 3: Restore Backup

Connect to Destination Server

ssh your_username@your_server_ip

Finally, in our new server, fire the following command,

ls /home/ | awk -F'[-.]' '{print $2}' | while read a; do
/scripts/killacct --user=$a
/scripts/restorepkg $a
done

Check the new server to ensure all cPanel accounts have been successfully migrated.

Leave a Reply

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