How to manually tansfer cpanel account
Creating a temporary directory using the mkdir command
To create a temporary directory, we will need to use the mkdir command.
$mkdir /home/user-temp (Cloudtechtiq)
This command will not produce any output. It will create a directory called user-temp inside of the /home directory.
Creating a compressed backup of public_html
Most of an account's disk space usage will occur within its public_html directory. So, we can reduce the size of the transfer by temporarily omitting the public_html directory from the transfer process. To do so, we will need to create a compressed backup of the directory.
To create a compressed backup, use the tar command. tar is an archive utility that is also capable of compressing the archive, when given the appropriate arguments.
$tar cvzf /home/user-temp/user-backup.tar.gz /home/user/public_html
In the example above, we are creating a compressed archive of the public_html directory at /home/user-temp/user-backup.tar.gz.
In this case, the tar utility receives:
2 input variables (/home/user-temp/user-backup.tar.gz and /home/user/public_html).
c Creates a new archive. We have to pass the tar utility the -c argument as it tells the utility to create a new archive versus, for example, extracting an existing archive.
v Prints to the CLI verbose information about what tar is doing. While this argument is not required, it makes it easy to see what is going on, should you encounter any errors.
z Uses the gzip compression utility to compress the new archive. This saves disk space. For more information about gzip, visit die.net's gzip man page.
f Causes the tar utility to read from and write to the specified file. In this case, we are writing to a file called user-backup.tar.gz.
Moving public_html using the mv command
Now that we created a compressed backup of the public_html directory, we can move the public_html directory to the temporary folder we created in the first step. To do so, we can use the mv command.
$mv /home/user/public_html /home/user-temp/
ALERT! Warning: You should never remove the public_html directory before the transfer is complete. You should make sure to keep a copy of the public_html directory at all times during the transfer process, so that the site can still be restored should you encounter any failures along the way.
Creating compressed backups of logs
Large websites often have large logs that accompany them. We can save ourselves more transfer time and disk space if we create a compressed backup of these logs.
We can find the domain's Apache weblogs in /usr/local/apache/domlogs.
Let's follow the same set of steps as above. We will create a compressed backup of the domain's weblogs and move the weblogs from their current location in usr/local/apache/domlogs/ to the temporary directory.
$root@Cloudtechtiq [~]# tar -cvzf /home/user-temp/user-logs.tar.gz /usr/local/apache/domlogs/example.com
$root@Cloudtechtiq [~]# mv /usr/local/apache/domlogs/example.com /home/user-temp/
The first command creates the compressed backup of the domain's logs in /home/user-temp/user-logs.tar.gz.
The second command moves the existing log files to the temporary directory.
Manually transferring the compressed backups using the scp command
There are several methods for transferring the compressed backups we have created. For this article, we'll use the scp protocol.
scp stands for secure copy. We can use this protocol to transfer files between servers. This method is fast and secure, and we will not have to use any arguments. We simply need to give the scp utility a file to move and place to go.
scp $local file to move $remote host:/path/to/new/file
For our purposes, let's pretend that we have root access on the remote machine, and that the remote host is domain.com. Along with the username and password for the remote server, we'll need to specify a path for the files we want to copy on the remote server. In this case, let's pretend the remote directory is /home/temp/.
$scp /home/user-temp/user-logs.tar.gz email@example.com:/home/temp/
$scp /home/user-temp/user-backup.tar.gz firstname.lastname@example.org:/home/temp/
Depending on the remote server's configuration, you may need to specify a few arguments to scp.
Argument Description Example
-P This argument allows you to specify a port number. You will need to specify the port number if the remote server does not use the default SSH port (22).
$scp -P 372 /home/user-temp/user-logs.tar.gz email@example.com:/home/temp/
-i This argument allows you to specify a key file if the remote server requires key-based authentication. scp -i key-name /home/user-temp/user-logs.tar.gz firstname.lastname@example.org:/home/temp/
-v This argument will cause the scp utility to produce verbose output. You should use this argument if you are experiencing problems with the scp utility. scp -v /home/user-temp/user-logs.tar.gz email@example.com:/home/temp/
These 2 commands will individually transfer the compressed backups we created of the user's public_html and Apache logs to the /home/temp directory on the other server. You will be prompted for the password when you connect to the other server, so make sure you have that information at hand.
Now that we have moved the 2 largest parts of the website manually, we can use the WHM Copy an account from another server interface to move the rest of the account information. This should be a speedy process.
Extracting the compressed backups
Once we have transferred our 2 compressed backups over and finished transferring the account, we'll need to extract the compressed backups to their appropriate locations. To do so, we'll need to use the tar utility again. This time, we will pass the tar utility a different set of arguments.
$tar -xvzf $file-to-extract.tar.gz $/path/to/place/contents/
As you can see, we simply need to change the -c argument to -x. This argument tells the tar utility to extract information from the files specified, rather than to create a file.
For example, let's restore the user's public_html to /home/user on the new system. We'll also need to extract the Apache logs to /usr/local/apache/domlogs.
$tar -xvzf /home/temp/user-backup.tar.gz /home/user/
$tar -xvzf /home/temp/user-logs.tar.gz /usr/local/apache/domlogs/
Once you have completed the transfer and restored the backups you have created, you should have successfully moved the account.
By Gaurav Sharma