Mass-Moving cPanel Accounts

If you’ve ever needed to move a ton of cPanel accounts from one server to another, you probably know the following:

  1. The multiple account move feature in WHM fails miserably
  2. It takes forever to do them one by one, esp. when you have other things to do

I figure the best way to mass-move accounts is by listing all the accounts in a file, then using a simple bash script to repetitively package all the accounts to they can be moved to another server.

First, you need to create a file (like users.txt) to list all the users you wish to move. If you’re only doing a few you can just go ahead and list the users in there manually, but if you’re doing like a whole server, you can get all the users in one file like so:

ls /var/cpanel/users > users.txt

You’ll then need to manually edit the users file and remove the ‘.’ and ”..’ entries, and any others that should not be included. The users.txt file should also be in a format like this:


Next, you may want to set up an SSH key between servers so all the cpmove files and be transferred automatically. If you don’t know how to do this, here is a simple and straight-through tutorial.

Create a bash script called ‘’ with the following lines:

#! /bin/bash
for i in `cat users.txt`; do /scripts/pkgacct $i; done
scp -r /home/cpmove* root@server:/home
echo "Account backups done" > email.txt
mail -vv -s "Account backups done" < email.txt

This will run cPanel backups up all the accounts listed in users.txt, scp them over to the new server, then email you when it’s done. Note that if you do not have SSH keys installed, you will have to manually type in the new server’s password when the script is ready to transfer the accounts over.

The on the new server you can use the same script and users.txt file, just change it around:

#! /bin/bash
for i in `cat users.txt`; do /scripts/restorepkg $i; done

This will restore all the user accounts that you copied over. From there, you’re all done!
One simple note: I’m not a shell programmer so I’m sure there are a lot better ways to accomplish this..if so, you can post them in a comment. The downside of using this method to move accounts is that all of the accounts are backed up in order so if you have a hundred some users, the backup files might be sitting on the server for hours until they are moved and restored, so you’ll want to make sure that your users are not making changes to their sites during the move process. Also, since the backup files are stored on the server it’s a good idea to figure out how much disk space you are going to need to avoid going over. You may be able to modify the script to do groups of 10-20 then delete the cpmove files if disk space is a concern.

Be Sociable, Share!

15 thoughts on “Mass-Moving cPanel Accounts

  1. Hey! I just wanted to say thanks for the cpmove script, it worked like a charm :)

    BTW, it’s VERY cool that a girl knows so much about this business, I’m not being sexiest or anything, it’s just that it’s rare.. :)



  2. I’m actually a boy, but don’t tell anyone because it might hurt my chances in the lesbian porn industry


    Glad you liked the script!

  3. Pingback: Robert's Tech blog
  4. This might be a stupid question, but does this script also copy email accounts as well and if not. Is their a way to do it?

  5. when you run a full cpanel backup, everything in the account is stored in the backup file including the email, databases, stats, logs, files, forwards, etc. In the move process outlined in my post you are using the /scripts/pkgacct script, which essentially is the same as running a full backup through cpanel only the filename is different.

  6. Do you know if it is possible to get a cpmove style backup from a full system backup, but that is not running anymore?
    Can you point me to any resources that will help me?

  7. It depends…did you do the system backup from WHM’s backup section? If so usually it will be in /cpbackup , but you’d have to check the configuration section to see what folder you had them run in.

  8. You can set the backup path in case you need it (i was out of space on that drive)

    change the first line with somethink like this

    for i in `cat users.txt`; do /scripts/pkgacct $i /your_backup_path/; done

  9. I know this is an old post, but I recommend something more like this to save space/server load considerations:

    #! /bin/bash
    ls -1 /var/cpanel/users/|sed ‘1,2d’>ulist
    while read user; do /scripts/pkgacct –skiphomedir $user; done email.txt
    mail -vv -s “Account backups done” < email.txt

    Then on the other server..

    /scripts/restorepkg $user
    while read user; rsync -a –progress -e 'ssh' root@server:/home/$user/ /home/$user/;done<ulist

  10. Crap… Not sure what happened there… After the /scripts/pkgacct line… should have:

    scp -r /home/cpmove* root@server:/home/
    scp -r /home/ulist* root@server:/home/

Leave a Reply

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