我们的服务器,每周五必需要做下备份linux 备份文件命令,但总是忘掉执行备份这件事情,或则是服务器备份做了,但没有做异地备份。所以通过定时任务手动备份,备份成功以后,在其它服务器里面通过定时任务scp命令手动拉取备份文件linux 备份文件命令,达到全部手动备份目的,只须要当天查看备份文件是否成功。

设置无需密码的ssh登录

假定A、B两服务器,如今须要在A机上用root登录B机,而不须要输入密码linux获取当前时间,那我们可根据下边的步骤来做:

1)在A机上生成锁匙对,执行以下命令:

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /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:
f6:61:a8:27:35:cf:4c:6d:13:22:70:cf:4c:c8:a0:23 root@host1

在/root/.ssh/路径下会生成id_rsa和id_rsa.pub,其中id_rsa是秘钥linux软件工程师培训,id_rsa.pub是私钥。

2)把在A机生成的id_rsa.pub拷贝到B机上:

ssh-copy-id -i ./id_rsa.pub root@ip

sship都会免密码手动登入主机

[root@LimeLinux~]#sship地址

Lastlogin:SunJan320:17:442021fromip

#echo”Authorizedusersonly.Allactivitymaybemonitoredandreported”>/etc/motd

[root@LimeLinux~]#

服务器设置定时备份文件

备份的linux命令_linux 备份文件命令_备份文件linux

[root@LimeLinux ~]# crontab -l
3 3 * * 5 /var/opt/ams/users/amssys/bin/ams_backup.sh -f /export/amsbackup/amsbackup$(date +"%Y%m%d").tar
3 2 * * 5 /bin/rm -f /export/amsbackup/amsbackup*
[root@LimeLinux ~]#

生成的文件将按时间格式命名:amsbackup20210101.tar

每周五下午2:03定时删掉之前的备份

备份的linux命令_linux 备份文件命令_备份文件linux

每周五下午3:03定时手动生成备份

scp定时拉取服务器备份

[root@LimeLinux ~]# crontab -l
10 3 * * 5 /bin/rm -rf /amsbackup/amsbackup*
10 4 * * 5 /usr/bin/scp root@ip:/export/amsbackup/amsbackup* /amsbackup/
[root@LimeLinux ~]#

每周五下午3:10定时删掉之前的备份

每周五下午4:10定时拉取服务器备份文件

注意:备份服务器的密码一定要保密,再保密,密码泄露很危险!!!

Author

这篇优质的内容由TA贡献而来

刘遄

《Linux就该这么学》书籍作者,RHCA认证架构师,教育学(计算机专业硕士)。

发表回复