使用 docker-compose 的 Wordpress Restic 备份脚本
这是我的 backup.sh,用于使用 Restic 备份具有 docker-compose 设置的 Wordpress 网站。
查看使用 Traefik 反向代理的 Wordpress docker-compose 配置了解推荐的 docker-compose 配置。
要使用 systemd 执行自动每日备份,请参见如何在 10 秒内创建 systemd 备份定时器和服务
查看如何在 Synology NAS 上安装 Restic REST 服务器了解更多关于如何在 Synology NAS 上激活 Restic REST 服务器的信息。
备份脚本
确保输入正确的用户名和密码(本示例中为 restic 和 abc123)、正确的 IP 地址(本示例中为 10.1.2.3)和端口(本示例中为 16383)。
同时,创建一个包含备份加密密码的 .restic_password 文件。单独备份该密码 - 没有它你无法恢复备份!
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 "Please create .restic_password with the backup encryption password AND BACKUP THAT PASSWORD SEPARATELY!!!"
exit 1
fi
echo "Initing repo, please ignore any 'already exists' errors"
if [ ! -f ".restic_inited" ]; then
# Run the restic init command
restic init
if [ $? -eq 0 ]; then # if init successful
# Create the initialization file
touch ".restic_inited"
echo "Restic initialized"
fi
fi
# Backup
source .env
docker-compose exec -T mariadb mysqldump -uroot -p${MARIADB_ROOT_PASSWORD} --all-databases | restic --verbose backup --stdin --stdin-filename="mariadb.sql"
# Backup files
restic --verbose backup backup.sh docker-compose.yml wordpress --exclude wordpress/wp-content/cacheIf this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow