使用 restic 简单备份 InvenTree Docker 部署
backup.sh
#!/bin/bash
export NAME=$(basename $(pwd))
export RESTIC_REPOSITORY=rest:http://restic:[email protected]:16383/$NAME
export RESTIC_PASSWORD_FILE=.restic_password
if [ ! -f "${RESTIC_PASSWORD_FILE}" ]; then
echo "请创建 .restic_password 并填入备份加密密码,同时务必单独备份该密码!!!"
exit 1
fi
echo "正在初始化仓库,请忽略任何 'already exists' 错误"
if [ ! -f ".restic_inited" ]; then
# 运行 restic init 命令
restic init
if [ $? -eq 0 ]; then # 如果初始化成功
# 创建初始化标记文件
touch ".restic_inited"
echo "Restic 已初始化"
fi
fi
# 以流式模式运行 PostgreSQL 备份
source .env
docker-compose exec -T inventree-db pg_dump -U${INVENTREE_DB_USER} ${INVENTREE_DB_NAME} | restic --verbose backup --stdin --stdin-filename="inventree-pgdump.sql"
# 备份目录与文件
echo "正在使用 restic 备份..."
restic --verbose backup \
inventree_data \
backup.sh \
docker-compose.yml \
--exclude "**/__pycache__" \
--exclude "inventree_data/static" \
--exclude "inventree_data/pgdb" \
--exclude "inventree_data/backup"
# 可选:遗忘旧备份并清理
# 按需调整以下保留策略:
# --keep-daily 31 # 保留 31 个每日快照
# --keep-weekly 52 # 保留 52 个每周快照
# --keep-monthly 24 # 保留 24 个每月快照
# --keep-yearly 10 # 保留 10 个每年快照
restic forget --keep-hourly 168 --keep-daily 31 --keep-weekly 52 --keep-monthly 24 --keep-yearly 10 --prune
echo "备份完成!"Check out similar posts by category:
InvenTree
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow