{"id":101206,"date":"2020-10-30T15:00:25","date_gmt":"2020-10-30T12:00:25","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/"},"modified":"2020-10-30T15:00:25","modified_gmt":"2020-10-30T12:00:25","slug":"how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/","title":{"rendered":"#How to Migrate a Linux Server To New Hardware \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a27eeb90fec5\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a27eeb90fec5\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/#Migration_Strategies\" >Migration Strategies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/#Installing_Packages\" >Installing Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/#Transferring_The_Servers_Disk_With_rsync\" >Transferring The Server\u2019s Disk With rsync<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/#Transferring_a_Database\" >Transferring a Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-migrate-a-linux-server-to-new-hardware-cloudsavvy-it\/#Switching_IPs_To_The_New_System\" >Switching IPs To The New System<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Migrate a Linux Server To New Hardware \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<figure id=\"attachment_7219\" style=\"width: 700px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7219 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/780c751b37a6fe8e416d557c5ead0e3e\/p\/uploads\/2020\/04\/101424eb.png\" alt=\"\" width=\"700\" height=\"300\" data-crediturl=\"https:\/\/www.shutterstock.com\/es\/image-photo\/network-cables-switch-firewall-cloud-computing-736216420\" data-credittext=\"Shutterstock\/asharkyu\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"imagecredit\"><a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/es\/image-photo\/network-cables-switch-firewall-cloud-computing-736216420\">Shutterstock\/asharkyu<\/a><\/span><\/figcaption><\/figure>\n<p>Whether you\u2019re upgrading to more powerful servers, moving to new regions, or adding new instances, migrating a Linux server can be made easier by implementing the proper strategies and knowing the right commands. We\u2019ll discuss how to move your server to a new machine with minimal hassle.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Migration_Strategies\"><\/span>Migration Strategies<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The simplest and most effective strategy is a blue green deployment\u2014get the new server up and running, and then when it\u2019s production ready, switch traffic over to it, and remove the old server once you\u2019ve verified there are no issues.\u00a0 With load balancing this process can h<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>en incrementally, further reducing chances of availability problems.<\/p>\n<p>A blue-green deployment involves copying over all the files, packages, and code on the old server over to the new one. This can be as simple as manually installing the necessary packages, such as an NGINX web server, and then copying over configuration from the existing server. You can also do a full disk backup, and create a new server from that.<\/p>\n<p>Of course, now is a perfect time to consider whether you can use containers or auto-scaling. Docker containers can be easily stopped, started, and migrated by copying the underlying data volumes (or using a shared data store like EFS). Auto Scaling differs depending on providers, but if you\u2019re adding a new copy of your server to meet growing demand, it may be right for your business. You can also use auto-scaling with Docker containers on many platforms like AWS ECS.<\/p>\n<p>The setup for both containers and auto-scaling requires you to do much of the same work you\u2019ll have to do to transfer the server manually, such as automating installing packages and your own code, so if you plan on migrating again in the future, you should consider now if you\u2019d be better off switching to containers, or setting up auto-scaling.<\/p>\n<p>If you\u2019re interested in containers, you can read our guide to getting started with Docker to learn more, or read our guide to using auto-scaling on AWS\u00a0or Google Cloud Platform.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Package Your Application&#8217;s Infrastructure with Docker<\/em><\/strong><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Installing_Packages\"><\/span>Installing Packages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you\u2019re not quite sure what you have installed on the old server, the best method to check is to get a list of all the installed services. This will show most of the major things you\u2019ll need to install:<\/p>\n<pre>service --status-all<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7666\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/dad4cda477ad12193922afe0fdfc0cea\/p\/uploads\/2020\/10\/e41bee7b.png\" alt=\"\" width=\"577\" height=\"288\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The reason for prefering listing services is because the list of installed packages can be <em>very <\/em>long, with every minor dependency also being installed. My Ubuntu test server had over 72000 packages installed, so the list of them isn\u2019t very useful considering they will all get installed anyway when installing the major services the new server needs.<\/p>\n<p>If you want, you can list all of them with the following command:<\/p>\n<pre>sudo apt list --installed<\/pre>\n<p>The search the package list for a specific package, you can use:<\/p>\n<pre>sudo apt -qq list program_name --installed<\/pre>\n<p>Either way, you\u2019ll want to make a list of the packages you need to install, and install them on the new server.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Transferring_The_Servers_Disk_With_rsync\"><\/span>Transferring The Server\u2019s Disk With rsync<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You could archive the disk with <code>tar<\/code>, but <code>tar<\/code>\u00a0is <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly meant to archive single files or directories, not an entire disk. If you\u2019re moving a lot of data, you may not have enough space to make a backup locally (perhaps that\u2019s even the reason for the upgrade!).<\/p>\n<p>In this case, you\u2019ll want to use the\u00a0<code>rsync<\/code>\u00a0command to upload up the data directly to the target server. <code>rsync<\/code>\u00a0will connect over SSH and sync up the two directories; in this case, we want to push the local directory to the remote server, like so:<\/p>\n<pre>rsync -azAP \/etc\/nginx username@remote_host:\/etc\/nginx<\/pre>\n<p>That\u2019s the whole command\u2014you should see a progress bar as it transfers (using compression with the <code>-z<\/code> flag), and when it\u2019s done, you\u2019ll see the files in the target directory on the new server. You may have to run this multiple times to copy each directory; you can use <a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"https:\/\/rsync.snipline.io\/\">this online <code>rsync<\/code>\u00a0command generator<\/a> to generate the command for each run.<\/p>\n<p>If you want, you can try copying the entire root filesystem to the new server, excluding some system files:<\/p>\n<pre>sudo rsync -azAP \/ --exclude={\"\/dev\/*\",\"\/proc\/*\",\"\/sys\/*\",\"\/tmp\/*\",\"\/run\/*\",\"\/mnt\/*\",\"\/<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>\/*\",\"\/lost+found\"} username@remote_host:\/<\/pre>\n<p>If you\u2019re just looking to make a backup of a few directories, you can use a simple\u00a0<code>tar<\/code>\u00a0command instead to generate a single file archive:<\/p>\n<pre>tar -czvf nginxconfig.tar.gz \/etc\/nginx<\/pre>\n<p>This outputs one file that you can transfer to the target server with <code>scp<\/code>\u00a0or over FTP. Then, extract the file to the target directory:<\/p>\n<pre>tar -xzvf nginxconfig.tar.gz -C \/etc\/nginx<\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Transferring_a_Database\"><\/span>Transferring a Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you need to transfer a database, you\u2019ll want to backup and dump the source database. For MySQL, that would be:<\/p>\n<pre>mysqldump -uUser -pPass -hHost --single-transaction database &gt; backup.bak<\/pre>\n<p>For MongoDB, that would be:<\/p>\n<pre>mongodump --host=mongodb.example.net --port=27017<\/pre>\n<p>Then you\u2019ll need to restore the database on the target server. For MySQL, that would be:<\/p>\n<pre>mysql -u [user] -p [database_name] &lt; [filename].sql<\/pre>\n<p>and for MongoDB, that would be:<\/p>\n<pre>mongorestore &lt;options&gt; &lt;connection-string&gt; &lt;directory or file to restore&gt;<\/pre>\n<p>For other databases, you should be able to find the relevant commands online.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Switching_IPs_To_The_New_System\"><\/span>Switching IPs To The New System<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Of course, you\u2019ll want to verify that everything works as intended before proceeding, but once it is, you\u2019ll want to switch traffic over to the new server.<\/p>\n<p>The simplest way to do this is to change your DNS records. Once updated, clients and services will be sent to the new server. This happens all at once though, so if you have a load balancer, it would be better to slowly transition traffic to the new instance.<\/p>\n<p>If you\u2019re on AWS, or a similar provider with Elastic IP addresses, you can swap over the address to point to the new server, which won\u2019t require a DNS update. From the Elastic IPs tab in the EC2 console, Action &gt; Associate Elastic IP Address.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-4192 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/ef0f29f336bd367cec2e0081e73f4d4c\/p\/uploads\/2020\/03\/4a912322.png\" alt=\"Change association on elastic IP address\" width=\"590\" height=\"207\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This will allow you to modify the association, which will instantly swap traffic to the new instance.\n<\/p><\/div>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/7664\/how-to-migrate-a-linux-server-to-new-hardware\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Migrate a Linux Server To New Hardware \u2013 CloudSavvy IT&#8221; Shutterstock\/asharkyu Whether you\u2019re upgrading to more powerful servers, moving to new regions, or adding new instances, migrating a Linux server can be made easier by implementing the proper strategies and knowing the right commands. We\u2019ll discuss how to move your server to a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":101207,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/04\/101424eb.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-101206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/101206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=101206"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/101206\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/101207"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=101206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=101206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=101206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}