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

This tutorial will help you migrate cPanel accounts from one server to another using the terminal. Whether you’re moving one account, all accounts, or just a few selected ones, this guide has you covered. Follow each step carefully, and take your time — there’s no rush!


🧳 Migrating a Single cPanel Account

  1. 1. Connect to the Source (Old) Server:

    Use SSH from your computer or terminal to access your old server:

    ssh your_username@old_server_ip

    Hint: Replace your_username with your actual SSH user, and old_server_ip with the IP address of your current server.

  2. 2. Create a Full Backup of the cPanel Account:

    Navigate to the home directory first:

    cd /home

    Now, generate the backup:

    /scripts/pkgacct cpanel_username

    Hint: Replace cpanel_username with the username of the account you want to move.

    Note: This process may take a few minutes depending on the account size. Just wait for it to finish before proceeding.

  3. 3. Transfer the Backup to the New Server:

    Run this command to transfer the backup file:

    rsync -av --progress /home/cpmove-cpanel_username.tar.gz root@new_server_ip:/home

    Hint: Replace cpanel_username and new_server_ip with the account username and your new server’s IP address.

    Note: This step may take several minutes, depending on the file size and connection speed.

  4. 4. Restore the Backup on the Destination (New) Server:

    Now SSH into the new server:

    ssh your_username@new_server_ip

    Then restore the account backup:

    /scripts/restorepkg cpmove-cpanel_username.tar.gz

    Note: After this, log in to WHM or cPanel to verify that everything is working correctly.


📦 Migrating All cPanel Accounts

  1. 1. Create Backups for All Accounts:

    Go to the home directory first:

    cd /home

    ⚠️ Warning: If there are any .tar.gz files already in the /home directory, consider removing them first to avoid uploading or restoring outdated backups by mistake.

    Then run this command to create backups for all existing cPanel accounts:

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

    Note: This may take quite a while depending on how many accounts you have and their sizes. Be patient and let it complete before continuing.

  2. 2. Transfer the Backups to the New Server:

    Use this command to send all the backup files to the new server:

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

    Hint: Replace new_server_ip with the IP address of your destination server.

  3. ⚠️ Warning: If there are any .tar.gz files already in the /home directory, consider removing them first. Keeping old backup files might cause confusion or lead
    to restoring the wrong account.

  4. 3. Restore All Accounts on the New Server:

    SSH into your new server:

    ssh your_username@new_server_ip

    Go to the home directory first:

    cd /home

    Run the following to restore each account:

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

    Note: This script removes any existing accounts with the same usernames before restoring. Afterward, check each account in WHM to confirm the migration was successful.


🎯 Migrating Selected (Multiple) cPanel Accounts

  1. Create Backups for Specific Accounts:

    First, move to the correct directory:

    cd /home

    ⚠️ Warning: If there are any .tar.gz files already in the /home directory, consider removing them first to avoid uploading or restoring outdated backups by mistake.

    Use this script to back up specific accounts:

    #!/bin/bash
    
    # List of cPanel accounts to create backups
    accounts=("account1" "account2" "account3")
    
    for account in "${accounts[@]}"; do
        /scripts/pkgacct $account
    done

    Hint: Replace “account1” “account2” “account3” with the actual usernames of the accounts you want to migrate.

    Note: You can add or remove usernames from the list as needed (ex “account1” “account2” “account3” “account4” “account5” …..). Make sure you wait until the script finishes creating all the backups before moving on.

  2. Transfer the Backups:

    Send the backup files to the new server:

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

    Hint: Replace new_server_ip with your new server’s IP address.

  3. ⚠️ Warning: If there are any .tar.gz files already in the /home directory, consider removing them first. Keeping old backup files might cause confusion or lead to restoring the wrong account.

  4. Restore the Selected Accounts:

    SSH into your new server:

    ssh your_username@new_server_ip

    Go to the home directory first:

    cd /home

    Restore each account with this command:

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

    Note: This will remove any conflicting accounts first, then restore them from the backups. Always double-check each site after the restore.


✅ Final Tips

  • 🔒 Always make sure SSH access is enabled on both servers and that your firewall allows the connection.
  • 🗂 If you are dealing with a large number of accounts, consider doing a few at a time to avoid overloading your server.
  • 🕒 Migration time depends on the number and size of accounts. A single account may take 5–15 minutes, while many accounts could take hours.
  • 🔁 After restoring, verify DNS settings, SSL certificates, and site functionality.
Share