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

Posted zxiaotian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rsync+shell脚本完成自动化备份相关的知识,希望对你有一定的参考价值。

服务端

# ls

Discuz_X3.1_SC_UTF8.zip

 

在客户端根目录下pwd

# pwd

/root

 

回到服务端

# scp -r Discuz_X3.1_SC_UTF8.zip [email protected]:/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.

[email protected]‘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 [email protected]:/root

[email protected]‘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 [email protected]:/root/ 

[email protected]‘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 [email protected]

The key‘s randomart image is:

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

|o+ . .o.*o.      |

|+oo  ..= o       |

|E++   o .        |

|==.o . .         |

|+.. .   S        |

|                 |

|                 |

|                 |

|                 |

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

 

 

 

[[email protected] ~]# 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 [email protected]

The key‘s randomart image is:

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

|                 |

|          .      |

|         . o     |

|          =      |

|        S o*     |

|       . ..oE.   |

|        o ..o+.  |

|       o + .+.o .|

|      . o   =* oo|

 

 

[[email protected] ~]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDyUAhJ2F1pCQWjEcqI8iy3yEat6O5lr9JHebI8U8K8m5xqV82KaoTCemSI2317uX8JZY2S78GBynhrIm+Ha2hmuY6D3FW871C1IOiDOcubJURsxCJuBc+45IoaFSum83DRghy/DsjwbQR5dk5GMQ3yXFfjHZY0X9f+WKj5i26Uz612HOMPoaotYGKOTVPoalWP/br/4OPIbhHkT42sQmpQugYu9gLYFN/kRz92AU70hbB56EzhEEb5SfUYH94nNqn+t2p4Pt7k5vdnP8d+IyaFyjvkRW3z6JUx1orblnUXnyO5obGmfVpAG0jy9dpI9fM7RgkAPQWTJ3YXKHpi1wrr [email protected]

 

 

[[email protected] ~]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKxC8fcUq+vkMWqS1q6jiKvWHPlHVV54JBuHLdZRM0nmeH7fbcSf+R+ZV402E2vznY9ZaQj/dd+JbCkERRmD14Ir8s+PuhHoTu5+O2MWKxPO3QHrpGB9peh1GRR4dKirCDbjaCpcfQzTVYD8bRxxySSX7IDtnxKfuQ+i1pkRCezefRRYtQARmYzgUi6oNFlXgludySVJ2Mp314hVPwEqyaEtLDdWxS2VBPjkeEwWhUgHzzD+549iZwdsgwJlu6zWmjUde6K/IWkM9euSn73p4CmhJPldo361O8UmNgUsTltlIIjJ9ssO89hevXgM0sr26NRDRtDfsDu8hu9BZcvs0b [email protected]

 

在服务端

[[email protected] ~]# vi /root/.ssh/authorized_keys

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

保存退出

再次发送发现无需密码

 技术分享图片

 

以上是关于rsync+shell脚本完成自动化备份的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

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

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