前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[Centos 7]免密码异地备份

[Centos 7]免密码异地备份

作者头像
贰叁壹小窝
发布2020-10-27 17:42:13
1.6K0
发布2020-10-27 17:42:13
举报
文章被收录于专栏:贰叁壹运维贰叁壹运维

环境:

代码语言:javascript
复制
  192.168.91.103 数据源服务器
  192.168.18.220 异地备份服务器

1.在192.168.91.103服务器生成秘钥文件

代码语言:javascript
复制
[root@Lenovobox3 file]# 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:
......

2.将公钥文件下发至异地备份服务器

代码语言:javascript
复制
[root@Lenovobox3 file]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.18.220
The authenticity of host '192.168.18.220 (192.168.18.220)' can't be established.
ECDSA key fingerprint is e1:98:4f:fd:c9:12:4d:4a:c8:b5:a5:c5:77:0c:65:ea.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': y
Please type 'yes' or 'no': yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are 
already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to 
install the new keys
root@192.168.18.220's password:    #输入异地备份服务器密码

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.18.220'"
and check to make sure that only the key(s) you wanted were added.

3.进行备份测试,当前IP是192.168.91.103

代码语言:javascript
复制
[root@Lenovobox3 file]# ls
backup_test.txt
[root@Lenovobox3 file]# pwd
/root/file

4.连接至异地备份服务器192.168.18.220,执行备份

代码语言:javascript
复制
[root@localhost ~]# rsync -avzp -e 'ssh -p 22' root@192.168.91.103:/root/file/backup_test.txt /data
receiving incremental file list
backup_test.txt

sent 30 bytes  received 90 bytes  240.00 bytes/sec
total size is 5  speedup is 0.04

5.验证备份数据

代码语言:javascript
复制
[root@localhost ~]# cd /data/
[root@localhost data]# ls
backup_test.txt
[root@localhost data]# cat backup_test.txt 
test

6.设置备份脚本

代码语言:javascript
复制
[root@localhost data]# vim backup.sh 
rsync -avzp -e 'ssh -p 22' --delete root@192.168.91.103:/data/ball/dirmap/database /data/103

7.设置定时任务

代码语言:javascript
复制
[root@localhost data]# crontab -e
0 0 *  * 6 /data/backup.sh > /data/log/log$(date +\%Y\%m\%d).txt
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-10-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档