Manually Rearranging Accounts

5/5 - (9 votes)

There was a situation today where I had to mass-move a bunch of accounts from one partition to another. WHM’s Rearrange an Account function does this one account at a time, but to move over 50 of them, a more scripted solution was necessary. Here’s how I did it on a live server without causing any downtime:

Scenario: Moving over 50 cPanel accounts from /home4 to /home3 on a live dedicated server

Step 1: Grab the list of users

Done with a simple one-liner:

for user in `cat /etc/passwd | grep /home/ | cut -d: -f1` ; do echo $user >> /root/users ; done

Step 1: Rsync all the data over

This part can be fairly CPU-intensive, so you may want to bandwidth-limit or renice the rsync which will slow the transfer, even if done locally. You need to copy the data on one disk to the other:

for user in `cat users` ; do rsync -av --bwlimit=8000 --delete /home4/$user /home3 ; done

You may want to run this command a few times depending on how much data is being moved over.

Step 3: Update configuration

Paste the following commands into a file (replacing the partition names with the ones pertaining to your server), chmod 755, and run:

for user in `cat users` ; do

replace /home4/ /home3/ — /var/cpanel/userdata/$user/*
replace /home4/ /home3/ — /etc/proftpd/$user
replace /home4/$user /home3/$user — /etc/passwd
ln -s /home3/$user /home4/$user
replace /home4/$user /home3/$user — /home3/$user/etc/*/passwd


Now, run:

/scripts/rebuildhttpconf && service httpd restart

service pure-ftpd restart (or proftp)

When you’re sure that everything is moved over, you can remove all the user data from the old partition.


  1. Frank Reply

    Note for anyone using this: Make sure to fix the replace commands with 2 hyphens – NOT ONE. Otherwise you’ll see `replace` block waiting on standard input. It seems the encoding or “rich text” on this website converted “–” to an HTML minus sign.

    Here’s an example (hopefully this will not be displayed wrongly like the original too):

    replace OLDSTRING NEWSTRING — /path/to/file

  2. AJ Reply

    one more important thing once this is all done:


    this updates /etc/userdatadomains with the new values for all homedirs.

Leave a Reply

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

Log in