使用 Omnibus 的 Gitlab Docker Restic 备份脚本
注意:相关文章:
配置备份脚本
首先,使用以下命令生成加密密码
generate_restic_password.sh
pwgen 30 > .restic_password确保单独备份此密码,否则所有数据都将丢失!
现在在 docker-compose.yml 所在的同一目录中创建 backup.sh:
gitlab_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
# Save Gitlab-internal PostgreSQL
docker-compose exec -u gitlab-psql gitlab pg_dump -h /var/opt/gitlab/postgresql/ -d gitlabhq_production | restic --verbose backup --stdin --stdin-filename="$NAME-pgdump.sql"
# Save directories
restic --verbose backup config data index backup.sh docker-compose.yml --exclude=data/gitlab-rails/shared/artifacts/ --exclude=data/postgresql自动启动备份脚本
查看如何在 10 秒内创建 Systemd 备份定时器和服务
TL;DR: 在 backup.sh 所在的目录中,运行
create_backup_service.sh
wget -qO- https://techoverflow.net/scripts/create-backup-service.sh | sudo bash /dev/stdinIf this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow