{"id":153,"date":"2020-04-13T10:17:41","date_gmt":"2020-04-13T02:17:41","guid":{"rendered":"http:\/\/wp.vicds.com\/?p=153"},"modified":"2024-10-28T12:11:07","modified_gmt":"2024-10-28T04:11:07","slug":"rsync-backup-full-system","status":"publish","type":"post","link":"https:\/\/wp.vicds.com\/?p=153","title":{"rendered":"rsync backup full system"},"content":{"rendered":"\n<p>\u53ef\u4ee5\u53c3\u8003<a href=\"https:\/\/www.linux.com\/training-tutorials\/how-backup-files-linux-rsync-command-line\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u9019\u88e1<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># backup\nsudo rsync -aAXv --delete --exclude=\/dev\/* --exclude=\/proc\/* --exclude=\/sys\/* --exclude=\/tmp\/* --exclude=\/run\/* --exclude=\/mnt\/* --exclude=\/media\/* --exclude=&quot;swapfile&quot; --exclude=&quot;lost+found&quot; --exclude=&quot;.cache&quot; --exclude=&quot;Downloads&quot; --exclude=&quot;.VirtualBoxVMs&quot; --exclude=&quot;.ecryptfs&quot; --exclude=&quot;vmware&quot; \/source \/destination\n\n# restore\nsudo rsync -aAXv --delete --exclude=&quot;lost+found&quot; \/backup \/system\n\n\u9078\u9805\n-a, --archive               archive mode; equals -rlptgoD (no -H,-A,-X)\n-A, --acls                  preserve ACLs (implies --perms)\n-X, --xattrs                preserve extended attributes\n-x, --one-file-system       don&#039;t cross filesystem boundaries\n-v, --verbose               increase verbosity\n--delete                delete extraneous files from destination dirs\n--partial    keep partially transferred files\n-\u2013append     append data onto shorter files\n--progress   show progress during transfer   This gives a bored user something to watch.....\n--include\n--exclude\n-e &quot;ssh -p 1234&quot;  \u7576port\u4e0d\u662f\u9810\u8a2d22\u6642\n\n\u5099\u4efd\u5be6\u4f8b\n#!\/bin\/bash\n\n#ntpdate time.stdtime.gov.tw\ngetDate=`date +&#039;%Y-%m-%d&#039;`\nsyncpath=&quot;\/mnt\/sda5\/&quot;\n\nif &#091; -d $syncpath$getDate ]; then\n        echo Already backup today!\n        exit 0\nelse\n        mkdir $syncpath$getDate \n        rsync -aAXv --delete --exclude=\/dev\/* --exclude=\/proc\/* --exclude=\/sys\/* --exclude=\/tmp\/* --exclude=\/run\/* --exclude=\/mnt\/* --exclude=\/media\/* --exclude=&quot;swapfile&quot; --exclude=&quot;lost+found&quot; --exclude=&quot;.cache&quot; --exclude=&quot;\/srv\/dev-disk-by-id-md-name-openmediavault.local-0&quot; \/ $syncpath$getDate\nfi\n\n\u9060\u7aef\u5099\u4efd\nrsync \u53c3\u6578 \/ user@IP:\/path\/\n\n\u5be6\u4f8b\nrsync -aAXv --progress --partial --append --exclude={&quot;\/dev\/*&quot;,&quot;\/proc\/*&quot;,&quot;\/sys\/*&quot;,&quot;\/tmp\/*&quot;,&quot;\/run\/*&quot;,&quot;\/mnt\/*&quot;,&quot;\/media\/*&quot;,&quot;\/mnt\/*&quot;,&quot;\/lost+found&quot;} \/ user@IP:path\/\n\n\n\n\u7528tar\u5099\u4efd\ntar -zcvpf ~\/backup.tar.gz --exclude=~\/backup.tar.gz --exclude=\/dev\/* --exclude=\/proc\/* --exclude=\/sys\/* --exclude=\/tmp\/* --exclude=\/run\/* --exclude=\/mnt\/* --exclude=\/media\/* --exclude=&quot;swapfile&quot; --exclude=&quot;lost+found&quot; \/\n\n\u9084\u539f \ntar -xvpzf \/backup.tgz -C \/ \nmkdir \/dev \/proc \/sys \/tmp \/run \/mnt \/media \/lost+found\n\n\u9ce5\u54e5\u7684\u7db2\u7ad9\u53ea\u6709\u4e0d\u58d3\u4ee5\u4e0b\u76ee\u9304, \u5728raspbian\u6e2c\u8a66OK\ntar --exclude=\/proc --exclude=\/mnt --exclude=\/tmp --exclude=~\/backup.tar.gz -zcvpf ~\/backup.tar.gz \/\n\u9ce5\u54e5\u7684\u9084\u539f\ntar -zxvf backup.tar.gz\n\n\u53c3\u8003\nhttps:&#047;&#047;help.ubuntu.com\/community\/BackupYourSystem\/TAR\n\n\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">\u53e6\u5916\u4e00\u7a2e\u7528tar\u7684\u505a\u6cd5  \n#\u5099\u4efd\nsu -\ncd \/\nsudo tar -cvpzf backup.tar.gz --exclude=\/backup.tar.gz --one-file-system \/\n\n# \u53ef\u80fd\u5728tar\u5f8c\u9762\u8981\u52a0\u4e0a\u9019\u4e9b\u53c3\u6578 --acls --xattrs --numeric-owner\n\n#\u9084\u539f\ncd \/\nsudo tar -xvpzf \/path\/to\/backup.tar.gz -C \/restore\/location --numeric-owner\n\n\u9019\u4e2d\u9593\u9084\u9700\u8981\u8abf\u6574\u65b0\u786c\u789f\u7684UUID\u9084\u6709\u5206\u5272.\n\n\u53c3\u6578\u8aaa\u660e\ntar - \u662f\u5efa\u7acb\u5b58\u6a94\u7684\u547d\u4ee4\u3002\u7dca\u63a5\u8457\u7531\u6bcf\u500b\u5b57\u6bcd\u4fee\u6539\uff0c\u4e0b\u9762\u5c07\u5c0d\u6bcf\u500b\u5b57\u6bcd\u9032\u884c\u8aaa\u660e\u3002\n\nc - \u5efa\u7acb\u65b0\u7684\u5099\u4efd\u5b58\u6a94\u3002\n\nv - \u8a73\u7d30\u6a21\u5f0f\uff0ctar\u5c07\u5217\u5370\u5b83\u5728\u87a2\u5e55\u4e0a\u6240\u505a\u7684\u4e8b\u60c5\u3002\n\np - \u4fdd\u7559\u5b58\u6a94\u4e2d\u653e\u7f6e\u7684\u6a94\u6848\u7684\u8a31\u53ef\u6b0a\u4ee5\u4fbf\u4ee5\u5f8c\u6062\u5fa9\u3002\n\nz - \u4f7f\u7528&#039;gzip&#039;\u58d3\u7e2e\u5099\u4efd\u6a94\u6848\u4ee5\u4f7f\u5176\u66f4\u5c0f\u3002\n\nf &lt;filename&gt; - \u6307\u5b9a\u5132\u5b58\u5099\u4efd\u7684\u4f4d\u7f6e\uff0cbackup.tar.gz\u662f\u6b64\u793a\u4f8b\u4e2d\u4f7f\u7528\u7684\u6a94\u540d\u3002\u5b83\u5c07\u5132\u5b58\u5728\u7576\u524d\u5de5\u4f5c\u76ee\u9304\u4e2d\uff0c\u5373\u4f7f\u7528cd\u547d\u4ee4\u6642\u8a2d\u5b9a\u7684\u76ee\u9304\u3002\n\n--exclude = \/example\/path - \u6b64\u6a21\u578b\u5f8c\u9762\u7684\u9078\u9805\u6307\u793atar \u4e0d\u8981\u5099\u4efd\u54ea\u4e9b\u76ee\u9304\u3002\u6211\u5011\u4e0d\u60f3\u5099\u4efd\u6240\u6709\u5167\u5bb9\uff0c\u56e0\u70ba\u67d0\u4e9b\u76ee\u9304\u4e0d\u662f\u5f88\u6709\u7528\u3002\u7b2c\u4e00\u500b\u6392\u9664\u898f\u5247\u6307\u793atar\u4e0d\u8981\u81ea\u884c\u5099\u4efd\uff0c\u9019\u5c0d\u65bc\u907f\u514d\u64cd\u4f5c\u671f\u9593\u7684\u932f\u8aa4\u5f88\u91cd\u8981\u3002\n\n--one-file-system - \u4e0d\u8981\u5728\u4e0d\u540c\u7684\u6a94\u6848\u7cfb\u7d71\u4e0a\u5305\u542b\u6a94\u6848\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5176\u4ed6\u6a94\u6848\u7cfb\u7d71\uff08\u4f8b\u5982\/ home\u5206\u5272\u69fd\u6216\u5b89\u88dd\u5728\/ media\u5099\u4efd\u4e2d\u7684\u5916\u90e8\u4ecb\u8cea\uff09\uff0c\u60a8\u9700\u8981\u55ae\u7368\u5099\u4efd\u5b83\u5011\uff0c\u6216\u7701\u7565\u6b64\u6a19\u8a8c\u3002\u5982\u679c\u7701\u7565\u6b64\u6a19\u8a8c\uff0c\u5247\u9700\u8981\u65b0\u589e\u5e7e\u500b--exclude =\u5f15\u6578\u4ee5\u907f\u514d\u60a8\u4e0d\u60f3\u8981\u7684\u6a94\u6848\u7cfb\u7d71\u3002\u9019\u4e9b\u5c07\u662froot\u4e2d\u7684\/proc\uff0c\/sys\uff0c\/mnt\uff0c\/media\uff0c\/run\u548c\/dev\u76ee\u9304\u3002\/proc\u548c\/sys\u662f\u865b\u64ec\u6a94\u6848\u7cfb\u7d71\uff0c\u5b83\u5c07\u8996\u7a97\u63d0\u4f9b\u7d66\u6b63\u5728\u57f7\u884c\u7684\u6838\u5fc3\u7684\u8b8a\u6578\uff0c\u56e0\u6b64\u60a8\u4e0d\u5e0c\u671b\u5617\u8a66\u5099\u4efd\u6216\u9084\u539f\u5b83\u5011\u3002 \/dev\u662f\u4e00\u500btmpfs\uff0c\u5176\u5167\u5bb9\u7531udev\u52d5\u614b\u5efa\u7acb\u548c\u522a\u9664\uff0c\u56e0\u6b64\u60a8\u4e5f\u4e0d\u60f3\u5099\u4efd\u6216\u6062\u5fa9\u5b83\u3002\u540c\u6a23\uff0c\/run\u662f\u4e00\u500btmpfs\uff0c\u5b83\u5132\u5b58\u6709\u95dc\u6b63\u5728\u57f7\u884c\u7684\u7cfb\u7d71\u7684\u4e0d\u9700\u8981\u5099\u4efd\u7684\u8b8a\u6578\u3002\n\nx - \u544a\u8a34tar\u7acb\u5373\u63d0\u53d6f\u9078\u9805\u6307\u5b9a\u7684\u6a94\u6848\u3002\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u5b58\u6a94\u662fbackup.tar.gz\n\n-C &lt;directory&gt; - \u6b64\u9078\u9805\u544a\u8a34tar\u5728\u89e3\u58d3\u7e2e\u4e4b\u524d\u66f4\u6539\u70ba\u7279\u5b9a\u76ee\u9304\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07\u9084\u539f\u5230\u6839\uff08\/mnt\uff09\u76ee\u9304\u3002\n\n--numeric-owner - \u6b64\u9078\u9805\u544a\u8a34tar\u6062\u5fa9\u6b78\u6a94\u4e2d\u6a94\u6848\u7684\u6578\u5b57\u6240\u6709\u8005\uff0c\u800c\u4e0d\u662f\u5339\u914d\u8981\u9084\u539f\u7684\u74b0\u5883\u4e2d\u7684\u4efb\u4f55\u4f7f\u7528\u8005\u540d\u7a31\u3002\u9019\u662f\u56e0\u70ba\u60a8\u8981\u6062\u5fa9\u7684\u7cfb\u7d71\u4e2d\u7684\u4f7f\u7528\u8005ID\uff1as\u4e0d\u4e00\u5b9a\u8207\u60a8\u7528\u65bc\u6062\u5fa9\u7684\u7cfb\u7d71\u5339\u914d\uff08\u4f8b\u5982\uff0cLive CD\uff09\u3002\n\nIconsPage \/warning.png \u9019\u5c07\u8986\u84cb\u6307\u5b9a\u88dd\u8f09\u4e2d\u7684\u6bcf\u500b\u6a94\u6848\u548c\u76ee\u9304\uff0c\u4e26\u4f7f\u7528\u5b58\u6a94\u4e2d\u7684\u6a94\u6848\u548c\u76ee\u9304\u3002\u6b78\u6a94\u5f8c\u5efa\u7acb\u7684\u4efb\u4f55\u6a94\u6848\u90fd\u4e0d\u6703\u5132\u5b58\u5728\u6b78\u6a94\u4e2d\uff0c\u56e0\u6b64\u5c07\u4fdd\u6301\u4e0d\u8b8a\u5141\u8a31\u6062\u5fa9\u9700\u8981\u5b8c\u6210\u7684\u6642\u9593\u3002\u63d0\u53d6\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u91cd\u65b0\u5efa\u7acb\u539f\u59cb\u5b58\u6a94\u4e2d\u672a\u5305\u542b\u7684\u76ee\u9304\uff0c\u56e0\u70ba\u60a8\u4f7f\u7528--exclude\u5c07\u5176\u6392\u9664\u3002\u9019\u4e0d\u9069\u7528\u65bc--one-file-system\u6392\u9664\u7684\u6a94\u6848\u7cfb\u7d71\u3002\u9019\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b8c\u6210\uff1a\n\nmkdir \/proc \/sys \/mnt \/media \n\u5b8c\u6210\u5f8c\uff0c\u91cd\u555f\u4e26\u5728\u9032\u884c\u5099\u4efd\u6642\u5c07\u6240\u6709\u5167\u5bb9\u6062\u5fa9\u5230\u7cfb\u7d71\u72c0\u614b\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">\u518d\u53e6\u4e00\u7a2e\u7684dd to ftp\n\u5148ftp\u5230\u4e3b\u6a5f\u4e0a\nftp \n&gt; open 192.168.1.1\n\u7136\u5f8c\u8f38\u5165\n&gt; put &quot;|dd if=\/dev\/sda bs=4M | gzip&quot; backup.gz\n\u8010\u5fc3\u7b49\u5f85....\n\n\u9084\u539f\n\u4e00\u6a23\u5148\u9023\u4e0a\u4e3b\u6a5f, \u7136\u5f8c\u8f38\u5165\n&gt; get backup.gz &quot;| gunzip | dd of=\/dev\/sda&quot;\n<\/code><\/pre>\n\n\n\n<p>\u53c3\u8003\u7b97  <a href=\"https:\/\/help.ubuntu.com\/community\/BackupYourSystem\/TAR\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/help.ubuntu.com\/community\/BackupYourSystem\/TAR<\/a><br>\u6e2c\u4e86\u4e00\u4e0b\u7528\u9019\u500b\u4e0d\u6703\u51fa\u73fetar error<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\"># \u5099\u4efd\n# cd \/ # THIS CD IS IMPORTANT THE FOLLOWING LONG COMMAND IS RUN FROM \/\n# tar -cvpzf backup.tar.gz \\\n--exclude=\/backup.tar.gz \\\n--exclude=\/proc \\\n--exclude=\/tmp \\\n--exclude=\/mnt \\\n--exclude=\/dev \\\n--exclude=\/sys \\\n--exclude=\/run \\ \n--exclude=\/media \\ \n--exclude=\/var\/log \\\n--exclude=\/var\/cache\/apt\/archives \\\n--exclude=\/usr\/src\/linux-headers* \\ \n--exclude=\/home\/*\/.gvfs \\\n--exclude=\/home\/*\/.cache \\ \n--exclude=\/home\/*\/.local\/share\/Trash \/\n\n# \u9084\u539f \u7528live usb\u958b\u6a5f, \u5047\u8a2dbackup.tar.gz\u5728usb\u88e1.\n# ls \/media\n# tar -xvpzf \/path\/to\/backup.tar.gz -C \/media\/whatever --numeric-owner\n# mkdir \/proc \/sys \/mnt \/media \n# sudo -s\n# for f in dev dev\/pts proc ; do mount --bind \/$f \/media\/whatever\/$f ; done\n# chroot \/media\/whatever\n# dpkg-reconfigure grub-pc\n\u60a8\u5c07\u770b\u5230\u4e00\u500b\u9078\u55ae\uff0c\u8a62\u554f\u60a8 grub \u61c9\u5b89\u88dd\u5728\u54ea\u500b\u78c1\u789f\u6a5f\u4e0a\u3002\u9078\u64c7\u96fb\u8166\u5c07\u5f9e\u4e2d\u555f\u52d5\u7684\u4efb\u4f55\u78c1\u789f\u6a5f\u3002<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u53c3\u8003\u9019\u88e1. \u53c3\u8003\u7b97 https:\/\/he [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=153"}],"version-history":[{"count":41,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":2357,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=\/wp\/v2\/posts\/153\/revisions\/2357"}],"wp:attachment":[{"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.vicds.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}