rsync+crontab定时同步文件到服务器

日常使用有两个服务器,一个用来跑实验,一个是存储服务器,由于实验服务器存储空间较少,需要定期备份和迁移数据到存储服务器

配置服务器之间ssh连接

首先在存储服务器检查内网ip地址

> ifconfig
... inet 192.168.1.12

然后参考我之前的博客,在实验服务器上配置~/.ssh/config

Host store
    HostName 192.168.1.12
    Port 22
    User wangyf
    IdentityFile ~/.ssh/id_rsa_store

rsync脚本

在~/.rsync_wangyf.sh写入rsync文件同步脚本

rsync -avPz --ignore-existing /home/wangyf/ wangyf@store:/your_path/

crontab定时同步

crontab -e

在打开的文件中写入

0 1 * * * bash rsync_wangyf.sh

意思是在每天凌晨1点运行文件同步命令。

查看当前定时任务

crontab -l

删除所有定时任务

crontab -r
posted @ 2025-05-22 18:12  yangfanww  阅读(68)  评论(0)    收藏  举报