{"id":377,"date":"2012-09-03T17:38:33","date_gmt":"2012-09-03T15:38:33","guid":{"rendered":"http:\/\/rexxer.kharkov.ru\/?p=377"},"modified":"2012-09-03T17:38:33","modified_gmt":"2012-09-03T15:38:33","slug":"freebsd-backup-and-restore","status":"publish","type":"post","link":"https:\/\/dety.net.ua\/?p=377","title":{"rendered":"FreeBSD backup and restore"},"content":{"rendered":"<p>\u0412\u0437\u044f\u0442\u043e \u043e\u0442\u0441\u044e\u0434\u0430: <a href=\"http:\/\/www.daemonforums.org\/showthread.php?t=2238\" target=\"_blank\">http:\/\/www.daemonforums.org\/showthread.php?t=2238<\/a><\/p>\n<p>Here i will cover how to backup\/restore (to file) FreeBSD using native utilities called <strong>dump <\/strong>and <strong>restore<\/strong><\/p>\n<p>note: dump and restore works only for UFS (aka FFS)<\/p>\n<p><span style=\"font-size: large\"><strong>Backing up system<\/strong><\/span><br \/>\nTo backup system you need to use dump utility<\/p>\n<p>backup:<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ dump -0Lauf \/path\/to\/backups\/ad0s1d.dump \/dev\/ad0s1d<\/pre>\n<\/div>\n<p>Backup and compress on the fly<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ dump -0Lauf - \/dev\/ad0s1d | bzip2 &gt; \/path\/to\/backups\/ad0s1d.dump<\/pre>\n<\/div>\n<p><strong>-0<\/strong> &#8211; means to backup entire filesystem<br \/>\n<strong>-f name<\/strong> &#8211; output to file\/device, or to stdout if you use <strong>&#8211;<\/strong><br \/>\n<strong>-a<\/strong> &#8211; you need this if you output to file.<br \/>\n<strong>-L<\/strong> &#8211; needed if you backup mounted filesystem<\/p>\n<p><span style=\"font-size: large\"><strong>Restoring system<\/strong><\/span><br \/>\nto restore system restart in single user mode<br \/>\nformat filesystem that you want to restore<br \/>\nin backup example, we backed up \/dev\/ad0s1d, so let&#8217;s format it now<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ newfs -U \/dev\/ad0s1d<\/pre>\n<\/div>\n<p>now you need to mount it<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 50px;text-align: left\">$ mkdir \/mnt\/target\n$ mount \/dev\/ad0s1d \/mnt\/target<\/pre>\n<\/div>\n<p>Let&#8217;s imagine you backed up files to usb stick (da0, in root directory)<br \/>\nwe need to mount it<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ mount -t msdosfs \/dev\/da0 \/mnt\/usb<\/pre>\n<\/div>\n<p><span style=\"color: red\"><br \/>\nImportant note: you need space in temp to be able to restore<br \/>\nif you run out of space in tmp, mount some filesystem somewhere and<br \/>\ncreate symbolic links from \/tmp and \/var\/tmp to that mount point<\/span><\/p>\n<p>now to restore from backup you need to cd to dir where you mounted partition that you want to restore<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ cd \/mnt\/target<\/pre>\n<\/div>\n<p>to restore from uncompressed backup<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ restore -rf \/mnt\/usb\/ad0s1d.dump<\/pre>\n<\/div>\n<p>to restore from compressed backup<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ bzcat \/mnt\/usb\/ad0s1d.dump.bz2 | restore rf -<\/pre>\n<\/div>\n<p>And that is it<br \/>\nnow you can delete file dumpdates (or something like that, check for weird file in target directory, in our case \/mnt\/target)<\/p>\n<p>now unmount filesystems and reboot<\/p>\n<p><span style=\"font-size: large\"><strong>Moving system<\/strong><\/span><br \/>\nyou can move system from disk to disk on fly with<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 82px;text-align: left\">$ newfs -U \/dev\/ad2s1a\n$ mount \/dev\/ad2s1a.... \/target\n$ cd \/target\n$ dump -0Lauf - \/dev\/ad1s1a  | restore -rf -<\/pre>\n<\/div>\n<p>you can do the same using sudo<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 50px;text-align: left\">$ sudo echo\n$ sudo dump -0Lauf - \/dev\/ad1s1a  | sudo restore -rf -<\/pre>\n<\/div>\n<p><span style=\"font-size: large\"><strong>Some notes<\/strong><\/span><br \/>\nyou can do incremental backups &#8211; backup everything and then backup only  files that have changed since (on current backup level) see manual for  more info<\/p>\n<p>you can use dump\/restore to clone your system to other PC&#8217;s<br \/>\nyou will probably need to copy Master Boot Record (MBR) as well<\/p>\n<p>to backup MBR:<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ dd if=\/dev\/ad0 of=\/path\/to\/mbr.img bs=512 count=1<\/pre>\n<\/div>\n<p>to restore MBR:<\/p>\n<div style=\"margin: 20px;margin-top: 5px\">\n<div class=\"smallfont\" style=\"margin-bottom: 2px\">Code:<\/div>\n<pre style=\"margin: 0px;padding: 6px;border: 1px inset;width: auto;height: 34px;text-align: left\">$ dd if=\/path\/to\/mbr.img of=\/dev\/ad0 bs=512 count=1<\/pre>\n<\/div>\n<p><span style=\"font-size: large\"><strong>Tips<\/strong><\/span><br \/>\n* I prefer to compress backup, you can guess why<\/p>\n<p>* if you backup \/usr you may delete content of ports directory<br \/>\nthis will speed up backup process, and reduce size of backup&#8230;<br \/>\nIt&#8217;s good thing because by the time you will restore \/usr from backups<br \/>\n\/usr\/ports will be outdated, and you will need to update them anyway.<br \/>\nAnd portsnap works very well (fast) in fetching ports<\/p>\n<p>* I prefer to do full backups, that way you can be 100% sure, there won&#8217;t<br \/>\nbe any confusing situations<\/p>\n<p>* if you want to do backups while using filesystem, make sure you haven&#8217;t<br \/>\ndeleted .snap directory, on partition that you want to backup<\/p>\n<p>* if you have backed up encrypted drive, you need to somehow encrypt backups<br \/>\nbecause if someone gets these files, he can restore them to his pc, and read your files at will. (I used this method in <a href=\"http:\/\/daemonforums.org\/showthread.php?t=2209\" target=\"_blank\">FreeBSD + Geli guide<\/a>, to encrypt drive, but process can be reversed)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412\u0437\u044f\u0442\u043e \u043e\u0442\u0441\u044e\u0434\u0430: http:\/\/www.daemonforums.org\/showthread.php?t=2238 Here i will cover how to backup\/restore (to file) FreeBSD using native utilities called dump and restore note: dump and restore works only for UFS (aka FFS) Backing up system To backup system you need to use dump utility backup: Code: $ dump -0Lauf \/path\/to\/backups\/ad0s1d.dump \/dev\/ad0s1d Backup and compress on the fly [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,13],"tags":[],"class_list":["post-377","post","type-post","status-publish","format-standard","hentry","category-freebsd","category-novosti"],"_links":{"self":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=377"}],"version-history":[{"count":0,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/377\/revisions"}],"wp:attachment":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}