For any webmaster, switching web server is a nightmare, especially when there is large number of files to move to a new server. After some bitter experiences, I have found out following methods to move your data files and database quickly and painlessly from one server to another. I’m sure these SSH commands will save your day.
These methods will copy/get that data files and database from your old server say Server A to new server say Server B without downloading anything to your PC. This way you will save some bandwidth and valuable time, and lot of anxious moments while your huge files are being uploaded when after lot of waiting and whining all you see is ‘script timed out’ message.
I’m assuming here that you have SSH access to your servers.
For data files, what I usually do is that I tar the files because file permissions are preserved and kept intact on the new server. First login through SSH to the Server A where your files are located.
Here are the commands:
cd /home/username-of-your-account/public_html tar -cvf backup-website.tar ./
Once it’s done, go to your new server say Server B and login through SSH:
Here are the commands:
cd /home/ username-of-your-account /public_html wget your-old-domain.com/backup-website.tar tar -xvf backup-website.tar
That’s it. One caveat here for extraction of tar file if you are logged in as root user. If you have any cPanel or HSphere panel available, you should use that to extract the tar file.
So either log in with your account user name or If you do extract the tar file with the root user, you probably want to check and make sure the correct owner and group are on your files you just extracted. You can check to see what they are by typing:
If the owner or group is wrong you can run this to change the owner:
chown -R owner.group ./
owner.group should be replaced with the owner name you want and the group name you want. This will recursively go through all your files and directories and changed them to the correct owner and group. One warning here, this command can change the owner and group for all of your files located on new server and can bring down your new server before even getting started. If the file permissions are not correct, you will see Forbidden error so only run this command “chown“ if you are really sure what you are doing. So be very careful for this command.
It would be far better and safer to extract the tar file using cPanel File Manager or logging in SSH with the hosting account name.
Hope that helps.