码迷,mamicode.com
首页 > 系统相关 > 详细

rsync+shell脚本完成自动化备份

时间:2018-09-18 20:52:38      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:which   ldd   3.1   scp   empty   ioi   utf8   permanent   root   

服务端

# ls

Discuz_X3.1_SC_UTF8.zip

 

在客户端根目录下pwd

# pwd

/root

 

回到服务端

# scp -r Discuz_X3.1_SC_UTF8.zip root@192.168.100.110:/root/

The authenticity of host ‘192.168.100.110 (192.168.100.110)‘ can‘t be established.

ECDSA key fingerprint is bd:e6:37:d2:73:28:f7:08:93:48:f4:40:61:81:a5:d1.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘192.168.100.110‘ (ECDSA) to the list of known hosts.

root@192.168.100.110‘s password:

Discuz_X3.1_SC_UTF8.zip       100%   10MB  10.0MB/s   00:00  

 

根目录下创建stor文件

#mkdir stor

将dvd中内容复制于stor中

#cp dvd.repo stor/

 

# scp -d stor root@192.168.100.110:/root

root@192.168.100.110‘s password:

stor: not a regular file

 

# yum list | grep rsync

# yum list installed | grep rsync

rsync.x86_64                         3.0.9-15.el7                  @anaconda/7.0

 

 

 

# systemctl start rsyncd

# netstat -anutp | grep 873

tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      7223/rsync         

tcp6       0      0 :::873                  :::*                    LISTEN      7223/rsync   

 

 

第一种密码传输

在根目录下随意创建一个文件并进行编辑

# mkdir zxt.txt

#vi /root/zxt.txt

向客户端传输zxt文件,

# scp -r /root/zxt.txt root@192.168.100.110:/root/ 

root@192.168.100.110‘s password:

zxt.txt                       100%    4     0.0KB/s   00:00

 

在客户端ls查询

# ls

 技术分享图片

 

 

第二种不需要密码来传输,

服务端客户端生成一个密钥

# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory ‘/root/.ssh‘.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

50:07:f2:61:81:e4:8a:58:3c:38:90:9d:e0:a6:b4:18 root@222

The key‘s randomart image is:

+--[ RSA 2048]----+

|o+ . .o.*o.      |

|+oo  ..= o       |

|E++   o .        |

|==.o . .         |

|+.. .   S        |

|                 |

|                 |

|                 |

|                 |

+-----------------+

 

 

 

[root@openstack-111 ~]# ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

ae:9d:25:35:df:e2:bb:b3:93:fd:2d:60:d8:90:13:fe root@openstack-111

The key‘s randomart image is:

+--[ RSA 2048]----+

|                 |

|          .      |

|         . o     |

|          =      |

|        S o*     |

|       . ..oE.   |

|        o ..o+.  |

|       o + .+.o .|

|      . o   =* oo|

 

 

[root@openstack-111 ~]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyUAhJ2F1pCQWjEcqI8iy3yEat6O5lr9JHebI8U8K8m5xqV82KaoTCemSI2317uX8JZY2S78GBynhrIm+Ha2hmuY6D3FW871C1IOiDOcubJURsxCJuBc+45IoaFSum83DRghy/DsjwbQR5dk5GMQ3yXFfjHZY0X9f+WKj5i26Uz612HOMPoaotYGKOTVPoalWP/br/4OPIbhHkT42sQmpQugYu9gLYFN/kRz92AU70hbB56EzhEEb5SfUYH94nNqn+t2p4Pt7k5vdnP8d+IyaFyjvkRW3z6JUx1orblnUXnyO5obGmfVpAG0jy9dpI9fM7RgkAPQWTJ3YXKHpi1wrr root@openstack-111

 

 

[root@222 ~]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKxC8fcUq+vkMWqS1q6jiKvWHPlHVV54JBuHLdZRM0nmeH7fbcSf+R+ZV402E2vznY9ZaQj/dd+JbCkERRmD14Ir8s+PuhHoTu5+O2MWKxPO3QHrpGB9peh1GRR4dKirCDbjaCpcfQzTVYD8bRxxySSX7IDtnxKfuQ+i1pkRCezefRRYtQARmYzgUi6oNFlXgludySVJ2Mp314hVPwEqyaEtLDdWxS2VBPjkeEwWhUgHzzD+549iZwdsgwJlu6zWmjUde6K/IWkM9euSn73p4CmhJPldo361O8UmNgUsTltlIIjJ9ssO89hevXgM0sr26NRDRtDfsDu8hu9BZcvs0b root@222

 

在服务端

[root@openstack-111 ~]# vi /root/.ssh/authorized_keys

将/root/.ssh/id_rsa.pub中内容写入

保存退出

再次发送发现无需密码

 技术分享图片

 

rsync+shell脚本完成自动化备份

标签:which   ldd   3.1   scp   empty   ioi   utf8   permanent   root   

原文地址:https://www.cnblogs.com/Zxiaotian/p/9671067.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!