Hugo博客公告弹窗

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

   
文章摘要
摘要小助理今天溜号啦……😜

将 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-09-17 13:18
clarity统计