{"id":363,"date":"2013-04-11T00:50:31","date_gmt":"2013-04-10T16:50:31","guid":{"rendered":"http:\/\/wp.iur.me\/?p=363"},"modified":"2022-11-06T20:15:07","modified_gmt":"2022-11-06T12:15:07","slug":"linuxvps%e8%87%aa%e5%8a%a8%e6%af%8f%e6%97%a5%e5%a4%87%e4%bb%bd%e6%96%87%e4%bb%b6%e5%92%8c%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%8a%e4%bc%a0ftp%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"https:\/\/www.iur.me\/?p=363","title":{"rendered":"LinuxVPS\u81ea\u52a8\u6bcf\u65e5\u5907\u4efd\u6587\u4ef6\u548c\u6570\u636e\u5e93\u4e0a\u4f20FTP\u7a7a\u95f4"},"content":{"rendered":"<p>\u6700\u8fd1\u7528\u7684\u662fBuyvm\u7684VPS\uff0c\u6027\u4ef7\u6bd4\u5f88\u7ed9\u529b\uff0c\u53ef\u662f\u56e0\u4e3a\u4ed6\u5bb6\u662fONEMAN\u8fd0\u8425\uff0c\u6015\u8dd1\u8def\u3002\u94b1\u7684\u635f\u5931\u4e0d\u91cd\u8981\uff0c\u624d\u51e0\u7f8e\u5143\u3002\u53ef\u6570\u636e\u5462\uff1f\u5982\u679c\u4e22\u4e86\uff0c\u5c31\u7070\u5e38\u6709\u8da3\u4e86\u3002<\/p>\n<p>\u6b64\u6587\u4ecb\u7ecd\u4e00\u79cd\uff0c\u6bcf\u5929\u81ea\u52a8\u5907\u4efd\u7f51\u7ad9\u4ee5\u53ca\u6570\u636e\u5e93\u6587\u4ef6\uff0c\u53d1\u9001EMAIL\u5230\u90ae\u7bb1\uff0c\u5e76\u4e0a\u4f20\u7f51\u7ad9\u548c\u6570\u636e\u52a0\u6587\u4ef6\u5230FTP\u7a7a\u95f4\uff0c\u81ea\u52a8\u5220\u9664\u65e7\u5907\u4efd\u7684\u65b9\u6cd5\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u9996\u5148\u5b89\u88c5EMAIL\u53d1\u9001\u7ec4\u4ef6\uff1a<\/p>\n<p>yum install sendmail mutt<\/p>\n<p>\u811a\u672c\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"http:\/\/www.vpsmm.com\/soft\/AutoBackupToFtp.sh\">http:\/\/www.vpsmm.com\/soft\/AutoBackupToFtp.sh<\/a><\/p>\n<p>\u811a\u672c\u4ee3\u7801\u5982\u4e0b\uff08\u6ce8\u610f\u4fee\u6539FTP\u670d\u52a1\u5668\u5730\u5740\u7528\u6237\u540d\u5bc6\u7801\uff09\uff1a<\/p>\n<p>#!\/bin\/bash<br \/>\n#\u4f60\u8981\u4fee\u6539\u7684\u5730\u65b9\u4ece\u8fd9\u91cc\u5f00\u59cb<br \/>\nMYSQL_USER=root \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #mysql\u7528\u6237\u540d<br \/>\nMYSQL_PASS=123456 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#mysql\u5bc6\u7801<br \/>\nMAIL_TO=cat@hostloc.com \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u6570\u636e\u5e93\u53d1\u9001\u5230\u7684\u90ae\u7bb1<br \/>\nFTP_USER=cat \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#ftp\u7528\u6237\u540d<br \/>\nFTP_PASS=123456 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #ftp\u5bc6\u7801<br \/>\nFTP_IP=imcat.in \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#ftp\u5730\u5740<br \/>\nFTP_backup=backup \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#ftp\u4e0a\u5b58\u653e\u5907\u4efd\u6587\u4ef6\u7684\u76ee\u5f55,\u8fd9\u4e2a\u8981\u81ea\u5df1\u5f97ftp\u4e0a\u9762\u5efa\u7684<br \/>\nWEB_DATA=\/home\/www \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8981\u5907\u4efd\u7684\u7f51\u7ad9\u6570\u636e<br \/>\n#\u4f60\u8981\u4fee\u6539\u7684\u5730\u65b9\u4ece\u8fd9\u91cc\u7ed3\u675f<\/p>\n<p>#\u5b9a\u4e49\u6570\u636e\u5e93\u7684\u540d\u5b57\u548c\u65e7\u6570\u636e\u5e93\u7684\u540d\u5b57<br \/>\nDataBakName=Data_$(date +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\nWebBakName=Web_$(date +%Y%m%d).tar.gz<br \/>\nOldData=Data_$(date -d -5day +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\nOldWeb=Web_$(date -d -5day +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\n#\u5220\u9664\u672c\u57303\u5929\u524d\u7684\u6570\u636e<br \/>\nrm -rf \/home\/backup\/Data_$(date -d -3day +&#8221;%Y%m%d&#8221;).tar.gz \/home\/backup\/Web_$(date -d -3day +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\ncd \/home\/backup<br \/>\n#\u5bfc\u51fa\u6570\u636e\u5e93,\u4e00\u4e2a\u6570\u636e\u5e93\u4e00\u4e2a\u538b\u7f29\u6587\u4ef6<br \/>\nfor db in `\/usr\/local\/mysql\/bin\/mysql -u$MYSQL_USER -p$MYSQL_PASS -B -N -e &#8216;SHOW DATABASES&#8217; | xargs`; do<br \/>\n(\/usr\/local\/mysql\/bin\/mysqldump -u$MYSQL_USER -p$MYSQL_PASS ${db} | gzip -9 &#8211; &gt; ${db}.sql.gz)<br \/>\ndone<br \/>\n#\u538b\u7f29\u6570\u636e\u5e93\u6587\u4ef6\u4e3a\u4e00\u4e2a\u6587\u4ef6<br \/>\ntar zcf \/home\/backup\/$DataBakName \/home\/backup\/*.sql.gz<br \/>\nrm -rf \/home\/backup\/*.sql.gz<br \/>\n#\u53d1\u9001\u6570\u636e\u5e93\u5230Email,\u5982\u679c\u6570\u636e\u5e93\u538b\u7f29\u540e\u592a\u5927,\u8bf7\u6ce8\u91ca\u8fd9\u884c<br \/>\necho &#8220;\u4e3b\u9898:\u6570\u636e\u5e93\u5907\u4efd&#8221; | mutt -a \/home\/backup\/$DataBakName -s &#8220;\u5185\u5bb9:\u6570\u636e\u5e93\u5907\u4efd&#8221; $MAIL_TO<br \/>\n#\u538b\u7f29\u7f51\u7ad9\u6570\u636e<br \/>\ntar zcf \/home\/backup\/$WebBakName $WEB_DATA<br \/>\n#\u4e0a\u4f20\u5230FTP\u7a7a\u95f4,\u5220\u9664FTP\u7a7a\u95f45\u5929\u524d\u7684\u6570\u636e<br \/>\nftp -v -n $FTP_IP &lt;&lt; END<br \/>\nuser $FTP_USER $FTP_PASS<br \/>\ntype binary<br \/>\ncd $FTP_backup<br \/>\ndelete $OldData<br \/>\ndelete $OldWeb<br \/>\nput $DataBakName<br \/>\nput $WebBakName<br \/>\nbye<br \/>\nEND<\/p>\n<p>\u7ed9\u811a\u672c\u6dfb\u52a0\u6267\u884c\u6743\u9650\uff1a<\/p>\n<p>chmod +x \/root\/AutoBackupToFtp.sh<\/p>\n<p>\u5229\u7528\u7cfb\u7edfcrontab\u5b9e\u73b0\u6bcf\u5929\u81ea\u52a8\u8fd0\u884c\uff1a<\/p>\n<p>crontab -e<\/p>\n<p>\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>00 00 * * * \/root\/AutoBackupToFtp.sh<\/p>\n<p>\u5176\u4e2d00 00\u4e3a\u65f6\u95f4\u5206\/\u5c0f\u65f6\uff0c\u53ef\u81ea\u884c\u4fee\u6539\uff0c\u4f8b\u5982\uff1a30 12 ***\uff0c\u5c31\u662f\u6bcf\u592912.30\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u3002<\/p>\n<p>\u9644\u4e00\u4e2a\u4f7f\u7528lftp\u5907\u4efd\u6587\u4ef6<\/p>\n<p>#!\/bin\/bash<br \/>\n#\u5b9a\u4e49\u6570\u636e\u5e93\u7684\u540d\u5b57\u548c\u65e7\u6570\u636e\u5e93\u7684\u540d\u5b57<br \/>\nDataBakName=Data_$(date +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\nWebBakName=Web_$(date +%Y%m%d).tar.gz<br \/>\n#\u5220\u9664\u672c\u57303\u5929\u524d\u7684\u6570\u636e<br \/>\nrm -rf \/home\/backup\/Data_$(date -d -3day +&#8221;%Y%m%d&#8221;).tar.gz \/home\/backup\/Web_$(date -d -3day +&#8221;%Y%m%d&#8221;).tar.gz<br \/>\n#\u5bfc\u51famysql\u6570\u636e\u5e93<br \/>\n\/usr\/local\/mysql\/bin\/mysqldump -uroot -ppassword &#8211;databases db1 &gt; \/home\/backup\/databackup.sql<br \/>\n#\u538b\u7f29\u6570\u636e\u5e93<br \/>\ntar zcf \/home\/backup\/$DataBakName \/home\/backup\/databackup.sql<br \/>\nrm -rf \/home\/backup\/databackup.sql<br \/>\n#\u538b\u7f29\u7f51\u7ad9\u6570\u636e<br \/>\ntar zcvf \/home\/backup\/$WebBakName \/home\/wwwroot<br \/>\n#\u4f7f\u7528lftp\u540c\u6b65\u5907\u4efd\u76ee\u5f55<br \/>\nlftp -u user,password -e &#8220;mirror -R &#8211;only-newer \/home\/backup \/backup&#8221;\u00a0<a href=\"ftp:\/\/ftp.yoursite.cn\/\">ftp.yoursite.cn<\/a><br \/>\nexit<br \/>\nEND<\/p>\n<p>\u8f6c\u8f7d\u81ea\uff1a<a href=\"http:\/\/imcat.in\/auto-backup-site-files-database-upload-ftp\/\">http:\/\/imcat.in\/auto-backup-site-files-database-upload-ftp\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u7528\u7684\u662fBuyvm\u7684VPS\uff0c\u6027\u4ef7\u6bd4\u5f88\u7ed9\u529b\uff0c\u53ef\u662f\u56e0\u4e3a\u4ed6\u5bb6\u662fONEMAN\u8fd0\u8425\uff0c\u6015\u8dd1\u8def\u3002\u94b1\u7684\u635f\u5931\u4e0d\u91cd\u8981\uff0c\u624d\u51e0\u7f8e\u5143\u3002 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[53],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-it","tag-vps"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=363"}],"version-history":[{"count":1,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":741,"href":"https:\/\/www.iur.me\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions\/741"}],"wp:attachment":[{"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iur.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}