{"id":164578,"date":"2019-12-10T09:00:06","date_gmt":"2019-12-10T01:00:06","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=164578"},"modified":"2019-11-25T09:58:57","modified_gmt":"2019-11-25T01:58:57","slug":"simple-shell-backup-script","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/simple-shell-backup-script.html","title":{"rendered":"Linux\u7cfb\u7edf\u914d\u7f6e\u6587\u4ef6\u7b80\u6613shell\u5907\u4efd\u811a\u672c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0cShell\u4fd7\u79f0\u58f3\uff08\u7528\u6765\u533a\u522b\u4e8e\u6838\uff09\uff0c\u662f\u6307\u201c\u4e3a\u4f7f\u7528\u8005\u63d0\u4f9b\u64cd\u4f5c\u754c\u9762\u201d\u7684\u8f6f\u4ef6\uff08\u547d\u4ee4\u89e3\u6790\u5668\uff09\u3002\u5b83\u7c7b\u4f3c\u4e8eDOS\u4e0b\u7684command.com\u548c\u540e\u6765\u7684cmd.exe\u3002\u5b83\u63a5\u6536\u7528\u6237\u547d\u4ee4\uff0c\u7136\u540e\u8c03\u7528\u76f8\u5e94\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u7ebf\u4e0a\u7684\u914d\u7f6e\u6587\u4ef6\u4ee5\u53ca\u5e94\u7528\u914d\u7f6e\u6587\u4ef6\u662f\u975e\u5e38\u6709\u5fc5\u8981\u8fdb\u884c\u5907\u4efd\u7684\uff0c\u4e0d\u6392\u9664\u80fd\u591f\u4e0a\u670d\u52a1\u5668\u7684\u670b\u53cb\u6ca1\u6709\u5907\u4efd\u5c31\u76f4\u63a5\u4fee\u6539\u51fa\u9519\u6216\u8005\u5176\u4ed6\u4eba\u5458\u8bef\u64cd\u4f5c\u7684\u60c5\u51b5\u3002\u73b0\u5728\u82b1\u4e86\u5341\u5206\u949f\u7b80\u5355\u5199\u4e86\u4e00\u4e2a\u5907\u4efd\u811a\u672c\uff0c\u53e6\u5916\u4e5f\u53ef\u4ee5\u81ea\u5df1\u52a0\u4e0a\u5176\u4ed6\u5907\u4efd\u811a\u672c\u8fdb\u53bb\u3002<\/p>\n

\u867d\u7b80\u5355\uff0c\u4f46\u6709\u4e86\u8fd9\u4e2a\u4e1c\u897f\u8fd8\u662f\u653e\u5fc3\u4e86\u4e0d\u5c11\uff0c\u518d\u4e5f\u4e0d\u7528\u62c5\u5fc3\u539f\u59cb\u914d\u7f6e\u6587\u4ef6\u627e\u4e0d\u5230\u4e86\u3002<\/p>\n

\r\n#!\/bin\/bash\r\n# bakup configfile  for system \u3001nginx \u3001 php \u3001ELK and so on\r\n#author:21yunwei\r\n#date:2017.4.22\r\ntime=`date +%Y%m%d`\r\nLOGFILE=\/backup\/configbak\/configbak.log\r\n [ ! -e \/backup\/configbak\/elkbak\/$time  ] && mkdir -p \/backup\/configbak\/elkbak\/$time\r\n [ ! -e \/backup\/configbak\/nginxbak\/$time  ] && mkdir -p \/backup\/configbak\/nginxbak\/$time\r\n [ ! -e \/backup\/configbak\/phpbak\/$time  ] && mkdir -p \/backup\/configbak\/phpbak\/$time\r\n [ ! -e \/backup\/configbak\/etcbak\/$time  ] && mkdir -p \/backup\/configbak\/etcbak\/$time\r\n \r\nfunction etcbak() {\r\n tar  zcf \/backup\/configbak\/etcbak\/$time\/etc$time.tar.gz  \/etc\/* \r\n}\r\n \r\nfunction nginxbak() {\r\ncp  -rfpu  \/usr\/local\/nginx\/conf\/*  \/backup\/configbak\/nginxbak\/$time\/\r\n}\r\nfunction phpbak() {\r\ncp  -rfpu  \/usr\/local\/php\/etc\/*  \/backup\/configbak\/phpbak\/$time\/\r\n}\r\nfunction elkbak() {\r\ncd  \/backup\/configbak\/elkbak\/$time && mkdir es logstash kibana\r\ncp -rfpu \/usr\/local\/ELK\/elasticsearch-5.1.1\/config\/*  \/backup\/configbak\/elkbak\/$time\/es\/\r\ncp -rfpu \/usr\/local\/ELK\/logstash-5.1.1\/config\/*  \/backup\/configbak\/elkbak\/$time\/logstash\/\r\ncp -rfpu \/usr\/local\/ELK\/kibana-5.1.1\/config\/*  \/backup\/configbak\/elkbak\/$time\/kibana\/\r\n}\r\n \r\n#start bak working:\r\netcbak\r\nnginxbak\r\nphpbak\r\nelkbak\r\n#bakwork end\r\n \r\nret=$?\r\nFINISHTIME=`date +%Y%m%d_%H%M%S`\r\n \r\n[ $ret -eq 0 ] && echo  \"configbak  finished, time: $FINISHTIME\">>  $LOGFILE || echo \"configbak  failed,please check time:$FINISHTIME\" >>  $LOGFILE\r\nfind  \/backup\/configbak\/ -type d  -mtime +15  |xargs rm -rf\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u7ebf\u4e0a\u7684\u914d\u7f6e\u6587\u4ef6\u4ee5\u53ca\u5e94\u7528\u914d\u7f6e\u6587\u4ef6\u662f\u975e\u5e38\u6709\u5fc5\u8981\u8fdb\u884c\u5907\u4efd\u7684\uff0c\u4e0d\u6392\u9664\u80fd\u591f\u4e0a\u670d\u52a1\u5668\u7684\u670b\u53cb\u6ca1\u6709\u5907\u4efd\u5c31\u76f4\u63a5\u4fee\u6539\u51fa\u9519\u6216\u8005\u5176\u4ed6\u4eba […]<\/p>\n","protected":false},"author":1479,"featured_media":148300,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-164578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/164578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=164578"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/164578\/revisions"}],"predecessor-version":[{"id":164959,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/164578\/revisions\/164959"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/148300"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=164578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=164578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=164578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}