在博客系统的运维中,数据备份是至关重要的环节。VanBlog作为一个现代化的博客系统,提供了完善的自动备份功能,不仅支持本地JSON数据备份,还集成了阿里云盘云端备份。本文将深入分析这个功能的实现原理、架构设计和优化过程。
VanBlog的自动备份功能位于 /admin/site/setting?tab=autoBackup,主要包含以下特性:
--skip参数避免重复传输在文章的增删改操作后,系统现在会自动触发标签同步功能,无需手动点击"同步标签数据"按钮。这个功能通过异步方式实现,不会影响用户体验。
原系统存在以下性能瓶颈:
渲染 = 把动态数据转换成静态HTML文件的过程
VanBlog使用Next.js的 ISR(Incremental Static Regeneration 增量静态再生成) 技术:
这个博客的方法是我看数据库数据的,不懂的不要轻易使用,直接用博客系统带的备份方案,直接导出json 和 图片。
VanBlog的数据主要存储在MongoDB中,包含以下重要数据:
需要保留的数据(文章数据):
articles - 文章内容drafts - 草稿categories - 分类tags - 标签(如果有的话)customPages - 自定义页面moments - 动态viewers - 浏览量统计visits - 访问记录需要重新配置的数据(系统配置):
metas - 站点信息(包含域名配置)users - 用户信息settings - 系统设置tokens - API令牌UV 是一个由 Astral 团队开发的高性能 Python 环境管理工具,它集成了包管理、虚拟环境管理和 Python 版本管理等功能。以下是使用 UV 管理 Python 环境的主要步骤和方法:
UV 可以通过多种方式安装:
bash展开代码pip install uv
bash展开代码curl -LsSf https://astral.sh/uv/install.sh | sh
powershell展开代码irm https://astral.sh/uv/install.ps1 | iex
uv --version 验证安装。| 操作 | Conda | uv |
|---|---|---|
| 创建环境 | conda create -n env python=3.11 | uv venv --python 3.11 |
| 激活环境 | conda activate env | source .venv/bin/activate |
| 安装包 | conda install numpy | uv pip install numpy |
| 查看已安装 | conda list | uv pip list |
| 导出依赖 | conda env export > env.yml | uv pip freeze > requirements.txt |
| 删除环境 | conda env remove -n env | rm -rf .venv |
| 速度 | 慢(几分钟) | 极快(几秒) |
vmware 的 dns 问题 导致 git pull失败:
nslookup github.com
github.com 的 DNS 解析是否正确,确认是否返回 GitHub 的真实 IP(如 20.205.243.166)。echo "nameserver 8.8.8.8" > /etc/resolv.conf
github.com 指向 127.0.0.1。ssh-keygen -f "/root/.ssh/known_hosts" -R "github.com"
ssh -T git@github.com
yes 后即可正常认证。更离谱的是,有时候这个文件只是软连接,可以看看这样:
bash展开代码ls -l /etc/resolv.conf
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
sudo chattr +i /etc/resolv.conf # 锁定文件(防止被覆盖)
sudo systemctl stop systemd-resolved # 禁用 systemd-resolved(可选)
sudo systemctl disable systemd-resolved
在 Ubuntu 服务器上执行以下命令:
bash展开代码# 安装必要的包
sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
# 添加 Caddy 官方 GPG 密钥
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# 添加 Caddy 仓库
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
# 安装 Caddy
sudo apt update
sudo apt install caddy
/.well-known/acme-challenge/ 路径发送HTTP请求验证域名控制权