网站远程自动备份方法分享






 



将vps中home/web目录打包并传到指定VPS的home目录



1.手动备份迁移

按时间戳打包

cd /home/ && tar czvf web_$(date +"%Y%m%d%H%M%S").tar.gz web


传输最新的tar压缩包到其他VPS

cd /home/ && ls -t /home/*.tar.gz | head -1 | xargs -I {} scp {} root@0.0.0.0:/home/


只保留3个压缩包

cd /home/ && ls -t /home/*.tar.gz | tail -n +4 | xargs -I {} rm {}



远端机器解压最新tar文件

cd /home/ && ls -t /home/*.tar.gz | head -1 | xargs -I {} tar -xzf {}





2.自动备份迁移

下载sh脚本

apt update -y && apt install -y wget sudo sshpass

cd /home

wget beifen.sh https://raw.githubusercontent.com/kejilion/sh/main/beifen.sh

chmod +x beifen.sh

nano beifen.sh


运行sh脚本

./beifen.sh


定时任务

(crontab -l ; echo "0 2 * * 1 /home/beifen.sh") | crontab -



3.注意

如果远端VPS重装系统了或是密码更改了。需要将之前连接的认证清除掉!

ssh-keygen -f "/root/.ssh/known_hosts" -R "0.0.0.0"  

0.0.0.0替换之前VPS的IP,清除认证!







评论

发表评论

此博客中的热门博文

科技lion官方一键脚本上线!VPS监控测试建站维护于一身的全能工具箱

2023国外的接码平台分享

CloudCone付费VPS分享 挺便宜的