1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| backup_path=/backup/rman remote_path='rman'
host='192.168.1.219' user='risuser' password='d3x_sK$8Ulm5'
(1) 将本地备份文件/backup/rman上传至远程服务器192.168.1.129的rman目录 lftp -u "$user,$password" -e "mirror -R $backup_path $remote_path; bye" $host
(2)下载 将远程服务器目录下的内容下载至本地/backup/rman lftp -u "$user,$password" -e "mirror $remote_path $backup_path; bye" $host
(3)将最新的文件到远程服务器 mirror --reverse --verbose --only-newer /local/path/to/backup /remote/path/to/backup --reverse:将操作从本地到远程 --verbose:显示详细信息 --only-newer:只上传较新的文件(修改时间更新的文件)
常用选项: -c, –continue :如果镜像过程中连接中断,重新开始 -e, –delete :删除不在远程服务器上的本地文件 -n, –only-newer :下载远程服务器上的新文件,不能和-c一起用 -R, –reverse :将本地文件镜像传输到远程服务器上 -v, –verbose[=level] :设置监视级别,范围0-3,0表示不输出,3表示输出全部
举例: mirror -R –delete –only-newer –verbose /home/aaa.com /public_html/web/aaa.com 将本地/home/aaa.com目录下的文件备份到远程服务器/public_html/web/aaa.com目录。
mirror –delete –only-newer –verbose /public_html/web /tmp 将远程服务器上/public_html/web目录下的文件备份到本地/tmp目录下。
(4)使用lftp的-e选项,例如: lftp -e “mirror -R –delete –only-newer –verbose /home/aaa.com /public_html/web/aaa.com” -p 21 -u admin,123456 ftp.aaa.com
注意:如果远程FTP服务器是Pure-FTPd [privsep] [TLS],执行命令会报错
WARNING: Certificate verification: Not trusted WARNING: Certificate verification: The certificate’s owner does not match hostname ‘www.xxx.com’ 并且停留在[Making data connection…],连接不上
需要编辑lftp的/etc/lftp.conf:
vim /etc/lftp.conf 在最后加入: debug 3 set ftp:ssl-auth TLS-P set ftp:use-feat no
再次尝试查看详情是否有报错。
PS:lftp默认使用PASV模式,如要使用PORT模式,登陆后执行set ftp:passive off,或者直接将其加入到/etc/lftp.conf中。 lftp多线程下载
(5)lftp还可以做为一个多线程下载工具。
常用选项:
pget -n :设置使用线程数。
-c :断点续传。
举例:
lftp -c “pget -n 10 http://sourceforge.net/projects/kvm/files/qemu-kvm/1.2.0/qemu-kvm-1.2.0.tar.gz”
(6)lftp使用问题
使用lftp的mirror命令备份时报550错
rm: Access failed: 550 dirname: Directory not empty
在lftp命令开头添加:
set ftp:list-options -a
是因为该文件夹下有隐藏文件,服务器默认不显示,所以删不掉。
设置lftp超时时间和重试次数
在lftp命令开头添加:
set net:timeout 10;set net:max-retries 2;set net:reconnect-interval-base 5;set net:reconnect-interval-multiplier 1;
综合这两点最终的命令为:
lftp -e “set net:timeout 10;set net:max-retries 2;set net:reconnect-interval-base 5;set net:reconnect-interval-multiplier 1;set ftp:list-options -a;mirror -R –delete –only-newer –verbose /home/aaa.com /public_html/web/aaa.com” -p 21 -u admin,123456 ftp.aaa.com
(7)脚本 #!/bin/bash
backup_path=/backup remote_path='/'
host='sftp://192.168.128.6:10022' user='dfyy' password='dfhospital123'
lftp -u "$user,$password" -e "mirror -R --delete --only-newer --verbose -c --parallel=6 $backup_path $remote_path; bye" $host
|