{"id":4929,"date":"2018-12-09T08:59:40","date_gmt":"2018-12-08T23:59:40","guid":{"rendered":"https:\/\/xe.bz\/blog\/?p=4929"},"modified":"2018-12-09T09:28:36","modified_gmt":"2018-12-09T00:28:36","slug":"%e7%b0%a1%e5%8d%98%e3%81%aa%e5%b1%a5%e6%ad%b4%e3%83%90%e3%83%83%e3%82%af%e3%82%a2%e3%83%83%e3%83%97%e3%82%92%e8%a1%8c%e3%81%86shell-script","status":"publish","type":"post","link":"https:\/\/akibabara.com\/blog\/4929.html","title":{"rendered":"\u7c21\u5358\u306a\u5c65\u6b74\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u884c\u3046Shell Script"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WordPress\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3084\u3001\u30c6\u30fc\u30de\u3084\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3069\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u306e\u6545\u969c\u3084\u8aa4\u64cd\u4f5c\u3067\u6d88\u3048\u3066\u3057\u307e\u3046\u4e8b\u614b\u306b\u5099\u3048\u3066\u3001\u5b9a\u671f\u7684\u306b\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u3057\u3066\u304a\u304f\u3068\u5b89\u5fc3\u3067\u3059\u3002\u81ea\u52d5\u7684\u306b\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u3082\u3042\u308a\u307e\u3059\u304c\u3001WordPress\u4ee5\u5916\u306e\u30d5\u30a1\u30a4\u30eb\u3082\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3067\u304d\u308b\u3088\u3001\u6c4e\u7528\u7684\u306a\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u6307\u5b9a\u3057\u305f\u56de\u6570\u5206\u306e\u5c65\u6b74\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002\u4ed5\u7d44\u307f\u306f\u5358\u7d14\u3067\u3001\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3057\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092<br>\u30fb\u6700\u65b0\u30d0\u30c3\u30af\u30a2\u30c3\u30d7 bakuup.0\/<br>\u30fb\u524d\u56de\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7 bakuup.1\/<br>\u30fb\u524d\u3005\u56de\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7 bakuup.2\/<br>\u306e\u3088\u3046\u306b\u30ed\u30fc\u30c6\u30fc\u30c8\u3059\u308b\u3060\u3051\u3067\u3059\u3002\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u6570\u304c\u6307\u5b9a\u56de\u6570\u306b\u9054\u3059\u308b\u3068\u53e4\u3044\u3082\u306e\u304b\u3089\u524a\u9664\u3055\u308c\u3066\u3044\u304f\u306e\u3067\u3001\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u6e9c\u307e\u3063\u3066\u30c7\u30a3\u30b9\u30af\u5bb9\u91cf\u3092\u5727\u8feb\u3059\u308b\u5fc3\u914d\u3082\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Shell Script<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\narchive=\/home\/backup\nbkname=db\nbkmax=30\n\nbkdir=$archive\/$bkname\nii=$bkmax\nwhile [ $ii -ge 0 ] ; do\n  jj=$(($ii-1))\n  [ -d $bkdir.$ii ] &amp;&amp; rm -rf $bkdir.$ii\n  [ -d $bkdir.$jj ] &amp;&amp; mv $bkdir.$jj $bkdir.$ii\n  ii=$jj\ndone\n\nmkdir $bkdir.0\nchmod 700 $bkdir.0\n\n## \u3053\u3053\u304b\u3089\nmysqldump --opt --all-databases --events --default-character-set=binary -u root --password=***** | gzip > $bkdir.0\/mysql-all.sql.gz\n## \u3053\u3053\u307e\u3067\n\nchmod 600 $bkdir.0\/*\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8aac\u660e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">archive=\u3000\u306f\u4fdd\u5b58\u5148\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002<br>bkname=\u3000\u306f\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u540d\u3067\u3001\u3053\u308c\u3092\u5909\u3048\u308c\u3070\u7570\u306a\u308b\u7a2e\u985e\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>bkmax=\u3000\u306f\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u306e\u4fdd\u5b58\u6570\u3002\u6700\u65b0\u72481+\u4fdd\u5b58\u6570\u306e\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u4f5c\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">##\u3053\u3053\u304b\u3089\u301c##\u3053\u3053\u307e\u3067 \u306e\u9593\u306f\u4efb\u610f\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3001\u3053\u3053\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u51fa\u529b\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u8a18\u8ff0\u3057\u305f\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u8a18\u8ff0\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u305d\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc\u5148\u3092&nbsp;$bkdir.0\/ \u306b\u3059\u308b\u3053\u3068\u3067\u3001\u3069\u3093\u306a\u30d5\u30a1\u30a4\u30eb\u3067\u3082\u7c21\u5358\u306b\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">crontab\u3067\u5b9a\u671f\u5b9f\u884c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u3042\u3068\u306fcrontab\u306b\u767b\u9332\u3057\u3066\u5b9a\u671f\u7684\u306b\u5b9f\u884c\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/cron.d\/backup \n52 5 * * * root \/path\/to\/db_backup.sh\n55 5 * * 7 root \/path\/to\/file_backup.sh<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f59\u8ac7<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u500b\u4eba\u7684\u306b\u306f\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306b <strong>rm -rf $xxxx<\/strong> \u3092\u5165\u308c\u308b\u306e\u3063\u3066\u306a\u3093\u304b\u6c17\u6301\u3061\u60aa\u3044\u3093\u3067\u3059\u3088\u306d\u3002\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5834\u5408\u306f$\u306e\u5909\u6570\u306b\u5165\u308b\u6587\u5b57\u5217\u304c\u6c7a\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u5927\u4e08\u592b\u3067\u3059\u304c\u3001\u3082\u3057\u4f55\u3089\u304b\u306e\u539f\u56e0\u3067 \/ \u304c\u5165\u3063\u3066\u3044\u305f\u3089 <strong>rm -rf \/<\/strong> \u30b3\u30de\u30f3\u30c9\u304c\u5b9f\u884c\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u79c1\u304c\u5b9f\u969b\u306b\u8d77\u3053\u3057\u305f\u3053\u3068\u304c\u3042\u308b\u60b2\u5287\u306f\u3053\u3093\u306a\u611f\u3058\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\nbasedir=\/home\nuser=$1\n\nrm -rf $basedir\/$user<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u3093\u3066\u6050\u308d\u3057\u3044\uff01\u5f15\u6570\u306b\u6307\u5b9a\u3057\u305f\u7279\u5b9a\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u30db\u30fc\u30e0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u5f15\u6570\u7121\u3057\u3067\u5b9f\u884c\u3059\u308b\u3068\u3001<strong>rm -rf \/home\/<\/strong> \u304c\u5b9f\u884c\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u6016\u3044\u3067\u3059\u306d\uff01\u3053\u308c\u306f\u5f15\u6570\u304c\u3061\u3083\u3093\u3068\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u304b\u306e\u30c1\u30a7\u30c3\u30af\u3092\u6020\u3063\u3066\u3044\u305f\u3053\u3068\u304c\u539f\u56e0\u3067\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3084\u3001\u30c6\u30fc\u30de\u3084\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3069\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u306e\u6545\u969c\u3084\u8aa4\u64cd\u4f5c\u3067\u6d88\u3048\u3066\u2026<\/p>\n","protected":false},"author":1,"featured_media":4930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[69,105],"class_list":{"0":"post-4929","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-other-topic","8":"tag-wordpress","9":"tag-shell-script","10":"three-column","11":"ar-three-column","12":"au-three-column"},"jetpack_featured_media_url":"https:\/\/akibabara.com\/blog\/wp-content\/uploads\/2018\/12\/backup.jpg","jetpack_shortlink":"https:\/\/wp.me\/pavCgQ-1hv","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/posts\/4929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/comments?post=4929"}],"version-history":[{"count":4,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/posts\/4929\/revisions"}],"predecessor-version":[{"id":4935,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/posts\/4929\/revisions\/4935"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/media\/4930"}],"wp:attachment":[{"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/media?parent=4929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/categories?post=4929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/akibabara.com\/blog\/wp-json\/wp\/v2\/tags?post=4929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}