As your business grows, the hardware needs of your website may increase, so sooner or later you might want to migrate your Linux Server to more powerful hardware.
Migrating a website is not like transferring files from one drive to another – it’s a bit more complicated, but, if you make it clear at once, which strategy you choose, this can be easily broken down into a few easier steps, so you will have your Linux migrated smoothly and easily.
Let’s have look at a few strategies that are available.
Blue-green deployment
One of the most common and easy strategies that you can apply to migrate your server is blue-green deployment. This strategy consists in first preparing your new server for operation, and once it is ready, you should switch its traffic to the new machine and then disable the old server if no problems occur. It is also great to perform it through load balancing as it allows this process to happen bit by bit, so you reduce the probability of problems.
This is similar to manually copying all packages, files, and code to the new server or making a disk backup and then using it for the server migration.
If you choose the blue-green deployment strategy, you also have to make up your mind whether you use containers or autoscaling. As for Docker containers, you can easily stop, start, and copy them. As for auto-scaling, you should make it plain with your hosting provider. The two approaches may be also sometimes combined.
Packages installation
If you have had your current server for a long time, and you don’t know anymore exactly which things you have on it, a nice idea is to request the catalog of installed services. Get it with the following command: service –status-all.
It makes more sense to prefer services over packages, as the packages are usually too many to make any use of them. If you want to get this list anyway, use the following command: sudo apt list –installed.
You can also search packages within certain packages with the command: sudo apt -qq list program_name –installed.
Get the list of packages installed and install them on the new server – simple as that.
Using rsync to transfer the disk of the server
In some cases, your disk may be too bulky to archive it using the tar command or to migrate it using backup. In this case, you may use the rsync command to upload the disk directly to the new server. The rsync command is aimed at synchronizing two directories, one of which will be on the old server, the other – on the new server. To make it work like this, you’ll need the following command: rsync -azAP /etc/nginx username@remote_host:/etc/nginx
Now, after copying a specific directory, you can manually copy the remaining directories in the same manner.
Alternatively, you can copy the whole root directory with the whole filesystem, but exclude certain system files: sudo rsync -azAP / –exclude={“/dev/*”,”/proc/*”,”/sys/*”,”/tmp/*”,”/run/*”,”/mnt/*”,”/media/*”,”/lost+found”} username@remote_host:/
If you are not going to copy all files, but just a couple of directories, you can apply the tar command to create archives: tar -czvf nginxconfig.tar.gz /etc/nginx
Migrating a database
To migrate a database, you will have to dump and backup the original database. For different databases you’ll require different commands:
MySQL: mysqldump -uUser -pPass -hHost –single-transaction database > backup.bak
MongoDB: mongodump –host=mongodb.example.net –port=27017
The further restoration of the database on the target server will require these commands:
MySQL: mysql -u [user] -p [database_name] < [filename].sql
MongoDB: mongorestore <options> <connection-string> <directory or file to restore>.
If you are using any other database, just look for the corresponding command on the WEB.
Adjusting the IPs
The last step of launching your server on new hardware is to make sure the traffic goes to it. To do it, the easiest and most straightforward way is to update your DNS records. To avoid a too rush transition if you want to reduce the load, it’s great to slow down this process by using a load balancer.
Conclusion
To provide the effective operation of your website, the server must fit its current requirements, you’ll have to update your capacities from time to time by means of migrating your server to new hardware. If you prefer Linux as the operating system, then we hope that this guide has made things clear for you. By the way, if you haven’t so far found an appropriate server, we recommend the debian virtual server hosting by HostZealot hosting provider. They have plenty of options for affordable prices and a high level of service, so you’ll definitely find what you need. This is the end of today’s article. Thank you for your attention and have a nice day!
Comment Policy
Your words are your own, so be nice and helpful if you can. Please, only use your REAL NAME, not your business name or keywords. Using business name or keywords instead of your real name will lead to the comment being deleted. Anonymous commenting is not allowed either. Limit the amount of links submitted in your comment. We accept clean XHTML in comments, but don't overdo it please. You can wrap code in [lang-name][/lang-name] tags.