Control panel migrations always involve risks. And, when the new panel does not have a one-click migration button, things become tougher.
In such cases, the best way for migration is to restore cPanel backup on the new server.
However, account restore can often generate permission errors, file format problems and many more.
At Bobcares, we frequently get migration requests from customers as part of our Server Migration Services.
Today, we’ll see how to restore cPanel backup on new server in a fail-safe way.
1. Taking cPanel backup
The very first step in this process is taking the cPanel backup. Basically, there are 2 methods to take the backup. One from the control panel and another from the command line using cPanel scripts.
From the cPanel, the user just has to navigate to the Backup option to get the account backup.
Additionally, cPanel has options to download Database, Home directory backups alone too.
To generate the backup from the command line, our Migration Engineers run the following command in the cPanel server.
scripts/pkgacct username
2. Copy to the new server
We now have the backup files available. As the next step, we need to copy the files to the new server. By default, we use scp command to bring the files over. The exact command will be
scp /home/cpmove-user.tar.gz root@x.x.x.x:/home
Here, x.x.x.x denotes the IP address of the new server.
When there are multiple accounts to copy we usually use a script to generate backup and copy them over to the new server. Again, we do this in batches to have better trackability.
3. Restore backup on the new server
At this point, we have the backup files in the new server. When the new server control panel does not support one-click restore, the only option is to restore via command line.
This involves restoring the website contents, databases, emails, etc. We’ll now see how our Migration Engineers restore each of them.
Restoring Web contents
The very first process in restoring the website is the copying of the web content. For this, we extract the cPanel backup file of the account. Then, there will be a homedir directory within the cpmove archive that holds the website contents. We copy the content of the public_html folder on to the website root directory of the new domain.
For example, when the website root directory of the domain on the new server is /var/www/html/mydomain.com, we copy the files using:
cp -rpf homedir/public_html /var/www/html/mydomain.com
At this point, our Migration Engineers set the permissions and ownership to the site user. This again depends on the user under which web server runs on the new server.
Importing databases
Most websites work with databases. Therefore, the next step is to import the databases over to the new server.
Here, we locate the MySQL files, database.sql and restore that file to the database using the below command.
mysql -u username -p databasename < database.sql
Also, we create a database user and grant permission too.
For example,
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';
We repeat the process for all databases and make sure that database users have adequate privileges too.
Copying mails
The final step in copying the account is the transfer of emails. When the source cPanel server and the new destination server have the mails in the same format, copying mails become rather easy.
For instance, when the source and destination servers have mails in Maildir format, we just need to copy the mail folders.
Here, we find mail folders from the backup at at home/user/mail/yourdomainname.com/mailaccountname/
We create the email accounts in the new server and copy the content from the old email folder to the new one.
That completes the account migration from cPanel server to the new server.
Common errors with backup restore
Though the migration appears pretty straight forward, customers end up in errors while following it. Let’s take a quick look at how our Migration Specialists correct them.
1. Corrupted backup file
In many cases, the corrupted backup files create problems while restoring.
tar: Exiting with failure status due to previous errors
This error primarily happens with the command-line backup generation. This means, for any reason, tar can’t add all of the specified files to the tar. One of the most common is not having read permission on one of the files.
In such cases, we identify the problem directory or file and exclude that from the tar backup. For example, to take a tar file excluding the sys, tmp folder, the command would be:
tar -cpzf /backups/domainbkp.tar.gz --exclude=tmp --exclude=sys
By excluding these directories, backup restore works just fine.
Again, when the user does not have permission to write the files in the archive also attributes to such errors. The easiest fix is to do the restore as the superuser root.
2. Incorrect privileges
Incorrect privileges is yet another common reason for errors when restoring cPanel backup on the new server. This can be on the files and folders or even with the database.
In such a scenario, our Migration Engineers set proper permissions on the files and folders to the site user.
Again, in the case of MySQL databases, we add the users to the proper databases.
[Trouble when restoring cPanel backup on new server? We can help you migrate the account]
Conclusion
In short, manual account migrations can be challenging. Improper migrations can result in website downtime and errors. Today, we saw the exact procedure on how to restore cPanel backup on new server. Our Migration Specialists do proper planning to avoid potential migration errors.
0 Comments