{"id":349,"date":"2012-04-30T21:15:27","date_gmt":"2012-04-30T21:15:27","guid":{"rendered":"http:\/\/blog.cyberwizzard.nl\/?p=349"},"modified":"2016-03-17T21:43:00","modified_gmt":"2016-03-17T20:43:00","slug":"backing-upcloning-a-linux-system-over-a-network","status":"publish","type":"post","link":"https:\/\/blog.cyberwizzard.nl\/?p=349","title":{"rendered":"Backing up\/cloning a linux system over a network"},"content":{"rendered":"<p>I had to perform this emergency procedure every now and then and I seem to reinvent the wheel every time so I reckoned it was time to document it.<\/p>\n<p>This time, its a failing master drive in a simple home server &#8211; without a RAID. The SMART monitoring has not yet caught on but the self-tests fail and some files are read-only as writes to the drive fail. Also the logs are full with SATA errors like: <code class=\"not-hl\">Apr 29 10:23:57 rivenscryr smartd[3621]: Device: \/dev\/sda, 18 Currently unreadable (pending) sectors<\/code><\/p>\n<p>To save the installation and all the files, I want to clone or backup the entire root filesystem (which is ext3, but that is not relevant) to a new drive (formatted ext4) in another machine. The reason to do this between machines can be numerous: perhaps you are migrating a live machine or (in this case) perhaps you worry that the current drive may fail when you power-cycle the system when the replacement drive is installed.<\/p>\n<h2 id=\"post-349-backup.2Fclone-over-network-recipe\">Backup\/Clone Over Network Recipe <a class=\"heading-link\" href=\"https:\/\/blog.cyberwizzard.nl\/?p=349#backup.2Fclone-over-network-recipe\" title=\"Link to this section\">&#8734;<\/a><\/h2>\n<ol>\n<li class=\"first-item\">Mount the root filesystem of the original machine on another location in order to have a clean copy:\n<pre class=\"code hl hl-bash\">&nbsp; <span class=\"kw2\">mkdir<\/span> <span class=\"sy0\">\/<\/span>mnt<span class=\"sy0\">\/<\/span>rootfs <span class=\"sy0\">&amp;&amp;<\/span> <span class=\"kw2\">mount<\/span> <span class=\"sy0\">\/<\/span> <span class=\"sy0\">\/<\/span>mnt<span class=\"sy0\">\/<\/span>rootfs <span class=\"re5\">-o<\/span> <span class=\"kw3\">bind<\/span><\/pre>\n<p>Check if it worked by listing the <code class=\"not-hl\">\/mnt\/rootfs\/<\/code> folder. Note that <code class=\"not-hl\">\/mnt\/rootfs\/proc<\/code> will be empty and <code class=\"not-hl\">dev<\/code> will be empty or very sparse.<\/li>\n<li>Use netcat and tar on the receiving machine (my case: random system with Ubuntu on USB stick and new HDD plugged in) to receive and write the data.\n<pre class=\"code hl hl-bash\">&nbsp; nc <span class=\"re5\">-l<\/span> <span class=\"nu0\">7777<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tar<\/span> <span class=\"re5\">-xz<\/span> <span class=\"re5\">-C<\/span> <span class=\"sy0\">\/<\/span>mnt<span class=\"sy0\">\/<\/span>targetdir<\/pre>\n<\/li>\n<li class=\"last-item\">\n<p>Use tar and netcat on the original machine to stream-copy the root filesystem over the network.<br \/>\n<strong>Big fat warning:<\/strong> My cloning is done on an internal, trusted network. You <strong>will be cloning using an unsecured stream<\/strong> over this network.<\/p>\n<pre class=\"code hl hl-bash\">&nbsp; <span class=\"kw2\">tar<\/span> <span class=\"re5\">-czp<\/span> <span class=\"re5\">--atime-preserve<\/span> <span class=\"re5\">--numeric-owner<\/span> \\\n&nbsp; &nbsp; <span class=\"re5\">--xattrs<\/span> <span class=\"re5\">--recursion<\/span> <span class=\"sy0\">\/<\/span>mnt<span class=\"sy0\">\/<\/span>rootfs <span class=\"sy0\">|<\/span> nc remotehost <span class=\"nu0\">7777<\/span><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p>Here is what all these options do:<\/p>\n<ul>\n<li class=\"first-item\">-c: Create a new archive<\/li>\n<li>-z: Use GZip compression to speed up the transfer<\/li>\n<li>-p: Preserve file permissions<\/li>\n<li>&#8211;atime-preserve: Do not update the accessed timestamp<\/li>\n<li>&#8211;numeric-owner: Copy using numeric ids only &#8211; useful when cloning into a foreign system<\/li>\n<li>&#8211;xattrs: Include ACL attributes and SElinux attributes<\/li>\n<li>&#8211;recursion: Recurse down into sub-folders<\/li>\n<li class=\"last-item\">&#8211;ignore-failed-read: Useful when a drive is heavily damaged and you only care to extract as much data as possible. Note: do not enable this by default as you might end up with an unusable clone if some files are missing. (Aka, this is a last resort option for non-functional clones)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I had to perform this emergency procedure every now and then and I seem to reinvent the wheel every time so I reckoned it was time to document it. This time, its a failing master drive in a simple home server &#8211; without a RAID. The SMART monitoring has not yet caught on but the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-349","post","type-post","status-publish","format-standard","hentry","category-linux-gentoolinux"],"views":5154,"_links":{"self":[{"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/posts\/349","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349"}],"version-history":[{"count":3,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":519,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=\/wp\/v2\/posts\/349\/revisions\/519"}],"wp:attachment":[{"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cyberwizzard.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}