服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

dirtysea 发表于 2014-12-3 19:06:52

LFTP mirror的高级应用

<font color="#111"><font face="宋体, tahoma, Srial, helvetica, sans-serif"><font style="font-size: 12px"><font style="font-size: 14px"><p style="line-height: 25px; text-indent: nullem; text-align: left;"><span style="color: rgb(1, 1, 1); font-size: 12px; line-height: 18px;"></span></p><div id="text" style="word-break: break-word; width: 570px; margin-top: 10px; margin-right: auto; margin-left: auto; line-height: 24px; font-size: 14px; white-space: normal; overflow: hidden;"><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">可以给 mirror 命令传入参数,控制同步的行为:&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--reverse 上传到FTP上,也可以使用 -R&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--delete: 如果远程目录下已经没有某个文件,而本地有,则删除这个文件。&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--only-newer: 只下载新的文件。mirror的判定新文件是通过文件大小和修改时间来判定的,我们可以使用&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--ignore-time,来屏蔽时间判定,这样mirror只通过大小来判断文件,同步速度加快。&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--exculde: 不包含某个目录。&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">--verbose: 详细输出。&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">比如:&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">mirror --delete --only-newer --verbose work bak/&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">自动备份服务器work<span id="2_nwp" style="width: auto; height: auto; float: none;"><a id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&amp;u=http%3A%2F%2Fwww%2Eth7%2Ecn%2Fsystem%2Flin%2F201212%2F35458%2Eshtml&amp;p=baidu&amp;c=news&amp;n=10&amp;t=tpclicked3_hc&amp;q=smileking_cpr&amp;k=%CE%C4%BC%FE%BC%D0&amp;k0=linux&amp;kdi0=8&amp;k1=%CE%C4%BC%FE%BC%D0&amp;kdi1=1&amp;k2=%CA%FD%BE%DD%B1%B8%B7%DD&amp;kdi2=1&amp;k3=%B1%B8%B7%DD&amp;kdi3=1&amp;k4=%B7%FE%CE%F1%C6%F7&amp;kdi4=1&amp;sid=ea6cb7cb7e042e0&amp;ch=0&amp;tu=u1682280&amp;jk=5465af9cf361810b&amp;cf=29&amp;fv=11&amp;stid=9&amp;urlid=0&amp;luki=2&amp;seller_id=1&amp;di=128" target="_blank" mpid="2" style="text-decoration: none; color: rgb(90, 128, 238);"><span style="color: rgb(0, 0, 255); font-size: 14px; width: auto; height: auto; float: none;">文件夹</span></a></span>,到本地当前目录的 bak文件夹下,并且删除已经不存在的文件,并且只下载最新的文件,再给出详细的输出。&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">用 lftp 的 -e 选项,把命令直接接在 lftp 之后:&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">lftp -u username,password -e”mirror --delete --only-newer --verbose /work bak/” ftpIP&nbsp;<br>&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">也可以用 at 选项指定备份的时间:&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">lftp at 01:00 -u username,password -e”mirror --delete --only-newer –verbose /work bak/” ftpIP&nbsp;</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;">这样每天 1 点就会执行<span id="1_nwp" style="width: auto; height: auto; float: none;"><a id="1_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&amp;u=http%3A%2F%2Fwww%2Eth7%2Ecn%2Fsystem%2Flin%2F201212%2F35458%2Eshtml&amp;p=baidu&amp;c=news&amp;n=10&amp;t=tpclicked3_hc&amp;q=smileking_cpr&amp;k=%B1%B8%B7%DD&amp;k0=linux&amp;kdi0=8&amp;k1=%CE%C4%BC%FE%BC%D0&amp;kdi1=1&amp;k2=%CA%FD%BE%DD%B1%B8%B7%DD&amp;kdi2=1&amp;k3=%B1%B8%B7%DD&amp;kdi3=1&amp;k4=%B7%FE%CE%F1%C6%F7&amp;kdi4=1&amp;sid=ea6cb7cb7e042e0&amp;ch=0&amp;tu=u1682280&amp;jk=5465af9cf361810b&amp;cf=29&amp;fv=11&amp;stid=9&amp;urlid=0&amp;luki=4&amp;seller_id=1&amp;di=128" target="_blank" mpid="1" style="text-decoration: none; color: rgb(90, 128, 238);"><span style="color: rgb(0, 0, 255); font-size: 14px; width: auto; height: auto; float: none;">备份</span></a></span>任务。</p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;"><br></p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;"><br></p><p style="border: medium none; margin: 15px auto 0px; padding: 0px; line-height: 25px;"><br></p><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);"><span style="color: rgb(128, 0, 0);"><strong>通过lftp的mirror模式(ncftp也有mirror模式)</strong></span></p><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">从FTP服务器上备份到本地</span></p><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">A、命令行方式</span>  </p><div class="wp_codebox_msgheader" style="width: 940.796875px; margin-top: 0.5em; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: silver; border-right-color: silver; border-left-color: silver; height: 22px; font-weight: bold; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: rgb(243, 248, 215); color: rgb(0, 0, 0); overflow: hidden; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-position: 100% 5px; background-repeat: no-repeat no-repeat;"><span class="right" style="float: right; text-align: right; padding-right: 5px; margin-right: 20px;"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" style="color: rgb(0, 119, 136); text-decoration: none; font-weight: normal !important; font-size: 14px !important; line-height: normal !important;"><span style="color: rgb(153, 204, 0);">?</span></a></sup></span><span class="left" style="float: left; font-family: tahoma, arial, verdana; padding: 2px 5px 2px 20px; margin-left: 5px; font-size: 14px; line-height: 18px; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/view_code.png); background-position: 0% 50%; background-repeat: no-repeat no-repeat;"><a style="color: rgb(0, 119, 136);">View Code</a>&nbsp;BASH</span><div class="codebox_clear" style="clear: both;"></div></div><div class="wp_codebox" style="color: rgb(17, 0, 0); width: 940.796875px; background-color: rgb(249, 249, 249); border: 1px solid silver; margin-bottom: 0.5em; overflow: auto; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px;"><table style="border: none; width: 940px;"><tbody><tr id="p12462"><td class="line_numbers" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px; text-align: right; background-color: rgb(221, 238, 255); color: rgb(102, 102, 102); overflow: visible; border-right-color: rgb(176, 190, 199); table-layout: auto; width: 10px;"><pre style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">1
2
3
4
5
6
7
</pre></td><td class="code" id="p1246code2" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px;"><pre class="bash" style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">lftp <span style="color: rgb(102, 0, 51);">-c</span> <span style="color: rgb(255, 0, 0);">"set ftp:list-options -a;
open ftp://user:password@your.ftp.com;
lcd ./web;
cd /web/public_html;
mirror --delete --use-cache --verbose --allow-chown
--allow-suid --no-umask --parallel=2 --exclude-glob .svn"</span>
  </pre></td></tr></tbody></table></div><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">B、脚本方式 </span> </p><div class="wp_codebox_msgheader" style="width: 940.796875px; margin-top: 0.5em; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: silver; border-right-color: silver; border-left-color: silver; height: 22px; font-weight: bold; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: rgb(243, 248, 215); color: rgb(0, 0, 0); overflow: hidden; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-position: 100% 5px; background-repeat: no-repeat no-repeat;"><span class="right" style="float: right; text-align: right; padding-right: 5px; margin-right: 20px;"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" style="color: rgb(0, 119, 136); text-decoration: none; font-weight: normal !important; font-size: 14px !important; line-height: normal !important;"><span style="color: rgb(153, 204, 0);">?</span></a></sup></span><span class="left" style="float: left; font-family: tahoma, arial, verdana; padding: 2px 5px 2px 20px; margin-left: 5px; font-size: 14px; line-height: 18px; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/view_code.png); background-position: 0% 50%; background-repeat: no-repeat no-repeat;"><a style="color: rgb(0, 119, 136);">View Code</a>&nbsp;BASH</span><div class="codebox_clear" style="clear: both;"></div></div><div class="wp_codebox" style="color: rgb(17, 0, 0); width: 940.796875px; background-color: rgb(249, 249, 249); border: 1px solid silver; margin-bottom: 0.5em; overflow: auto; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px;"><table style="border: none; width: 940px;"><tbody><tr id="p12463"><td class="line_numbers" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px; text-align: right; background-color: rgb(221, 238, 255); color: rgb(102, 102, 102); overflow: visible; border-right-color: rgb(176, 190, 199); table-layout: auto; width: 10px;"><pre style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p1246code3" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px;"><pre class="bash" style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;"><span style="color: rgb(102, 102, 102); font-style: italic;">#!/bin/bash</span>
<span style="color: rgb(0, 120, 0);">HOST</span>=<span style="color: rgb(255, 0, 0);">"your.ftp.host.dom"</span>
<span style="color: rgb(0, 120, 0);">USER</span>=<span style="color: rgb(255, 0, 0);">"username"</span>
<span style="color: rgb(0, 120, 0);">PASS</span>=<span style="color: rgb(255, 0, 0);">"password"</span>
<span style="color: rgb(0, 120, 0);">LCD</span>=<span style="color: rgb(255, 0, 0);">"/path/of/your/local/dir"</span>
<span style="color: rgb(0, 120, 0);">RCD</span>=<span style="color: rgb(255, 0, 0);">"/path/of/your/remote/dir"</span>
lftp <span style="color: rgb(102, 0, 51);">-c</span> <span style="color: rgb(255, 0, 0);">"set ftp:list-options -a;
open ftp://<span style="color: rgb(0, 120, 0);">$USER</span>:<span style="color: rgb(0, 120, 0);">$PASS</span>@<span style="color: rgb(0, 120, 0);">$HOST</span>;
lcd <span style="color: rgb(0, 120, 0);">$LCD</span>;
cd <span style="color: rgb(0, 120, 0);">$RCD</span>;
mirror --delete <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --verbose <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-dir-to-exclude/ <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-file-to-exclude <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-file-group-to-exclude* <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob other-files-to-esclude"</span>
  </pre></td></tr></tbody></table></div><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">从本地恢复到FTP服务器上</span></p><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">A、命令行方式</span>  </p><div class="wp_codebox_msgheader" style="width: 940.796875px; margin-top: 0.5em; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: silver; border-right-color: silver; border-left-color: silver; height: 22px; font-weight: bold; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: rgb(243, 248, 215); color: rgb(0, 0, 0); overflow: hidden; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-position: 100% 5px; background-repeat: no-repeat no-repeat;"><span class="right" style="float: right; text-align: right; padding-right: 5px; margin-right: 20px;"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" style="color: rgb(0, 119, 136); text-decoration: none; font-weight: normal !important; font-size: 14px !important; line-height: normal !important;"><span style="color: rgb(153, 204, 0);">?</span></a></sup></span><span class="left" style="float: left; font-family: tahoma, arial, verdana; padding: 2px 5px 2px 20px; margin-left: 5px; font-size: 14px; line-height: 18px; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/view_code.png); background-position: 0% 50%; background-repeat: no-repeat no-repeat;"><a style="color: rgb(0, 119, 136);">View Code</a>&nbsp;BASH</span><div class="codebox_clear" style="clear: both;"></div></div><div class="wp_codebox" style="color: rgb(17, 0, 0); width: 940.796875px; background-color: rgb(249, 249, 249); border: 1px solid silver; margin-bottom: 0.5em; overflow: auto; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px;"><table style="border: none; width: 940px;"><tbody><tr id="p12464"><td class="line_numbers" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px; text-align: right; background-color: rgb(221, 238, 255); color: rgb(102, 102, 102); overflow: visible; border-right-color: rgb(176, 190, 199); table-layout: auto; width: 10px;"><pre style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">1
2
3
4
5
6
7
</pre></td><td class="code" id="p1246code4" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px;"><pre class="bash" style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">lftp <span style="color: rgb(102, 0, 51);">-c</span> <span style="color: rgb(255, 0, 0);">"set ftp:list-options -a;
open ftp://user:password@your.ftp.com;
lcd ./web;
cd /web/public_html;
mirror --reverse --delete --use-cache --verbose --allow-chown
--allow-suid --no-umask --parallel=2 --exclude-glob .svn"</span>
  </pre></td></tr></tbody></table></div><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  <span style="color: rgb(128, 0, 0);">B、脚本方式 </span> </p><div class="wp_codebox_msgheader" style="width: 940.796875px; margin-top: 0.5em; border-width: 1px 1px 0px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-color: silver; border-right-color: silver; border-left-color: silver; height: 22px; font-weight: bold; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/arrow-square.gif); background-color: rgb(243, 248, 215); color: rgb(0, 0, 0); overflow: hidden; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-position: 100% 5px; background-repeat: no-repeat no-repeat;"><span class="right" style="float: right; text-align: right; padding-right: 5px; margin-right: 20px;"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" style="color: rgb(0, 119, 136); text-decoration: none; font-weight: normal !important; font-size: 14px !important; line-height: normal !important;"><span style="color: rgb(153, 204, 0);">?</span></a></sup></span><span class="left" style="float: left; font-family: tahoma, arial, verdana; padding: 2px 5px 2px 20px; margin-left: 5px; font-size: 14px; line-height: 18px; background-image: url(http://www.mike.org.cn/wp-content/plugins/wp-codebox/images/view_code.png); background-position: 0% 50%; background-repeat: no-repeat no-repeat;"><a style="color: rgb(0, 119, 136);">View Code</a>&nbsp;BASH</span><div class="codebox_clear" style="clear: both;"></div></div><div class="wp_codebox" style="color: rgb(17, 0, 0); width: 940.796875px; background-color: rgb(249, 249, 249); border: 1px solid silver; margin-bottom: 0.5em; overflow: auto; font-family: Arial, Tahoma; font-size: 12px; line-height: 20px;"><table style="border: none; width: 940px;"><tbody><tr id="p12465"><td class="line_numbers" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px; text-align: right; background-color: rgb(221, 238, 255); color: rgb(102, 102, 102); overflow: visible; border-right-color: rgb(176, 190, 199); table-layout: auto; width: 10px;"><pre style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p1246code5" style="vertical-align: top; padding-top: 2px; padding-bottom: 2px;"><pre class="bash" style="border: none; background-image: none; width: auto; float: none; clear: none; overflow: visible; line-height: 1.333;"><span style="color: rgb(102, 102, 102); font-style: italic;">#!/bin/bash</span>
<span style="color: rgb(0, 120, 0);">HOST</span>=<span style="color: rgb(255, 0, 0);">"your.ftp.host.dom"</span>
<span style="color: rgb(0, 120, 0);">USER</span>=<span style="color: rgb(255, 0, 0);">"username"</span>
<span style="color: rgb(0, 120, 0);">PASS</span>=<span style="color: rgb(255, 0, 0);">"password"</span>
<span style="color: rgb(0, 120, 0);">LCD</span>=<span style="color: rgb(255, 0, 0);">"/path/of/your/local/dir"</span>
<span style="color: rgb(0, 120, 0);">RCD</span>=<span style="color: rgb(255, 0, 0);">"/path/of/your/remote/dir"</span>
lftp <span style="color: rgb(102, 0, 51);">-c</span> <span style="color: rgb(255, 0, 0);">"set ftp:list-options -a;
open ftp://<span style="color: rgb(0, 120, 0);">$USER</span>:<span style="color: rgb(0, 120, 0);">$PASS</span>@<span style="color: rgb(0, 120, 0);">$HOST</span>;
lcd <span style="color: rgb(0, 120, 0);">$LCD</span>;
cd <span style="color: rgb(0, 120, 0);">$RCD</span>;
mirror --reverse <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --delete <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --verbose <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-dir-to-exclude/ <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-file-to-exclude <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob a-file-group-to-exclude* <span style="color: rgb(0, 0, 153); font-weight: bold;">\
</span>       --exclude-glob other-files-to-esclude"</span>
  </pre></td></tr></tbody></table></div><p style="padding-bottom: 10px; color: rgb(51, 51, 51); font-family: Arial, Tahoma; font-size: 12px; line-height: 20px; background-color: rgb(243, 243, 243);">  两种方式间主要的差别就是在–reverse选项上,有这个选项就是put files,反之则是get files。</p></div></font></font></font></font>
页: [1]
查看完整版本: LFTP mirror的高级应用