返回

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

   
摘要GPT
摘要小助理暂时失联跑路啦……😜

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

手动备份迁移

按时间戳打包

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 {}

自动备份迁移

下载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 -
知识共享许可证 CC BY-NC-SA 4.0
最后更新于 2024-07-17 18:28
使用 Hugo 构建
主题 hugo-magic小洋葱 魔改 由 Jimmy 设计
Written by Human, Not by AI