This commit is contained in:
chinky 2019-06-04 22:17:16 +08:00
parent ecfdc98e5f
commit 487b4a7826
3 changed files with 18 additions and 34 deletions

View File

@ -1,36 +1,17 @@
#!/bin/bash
# 自动备份时使用以下命令,需要root权限
# /bin/bash /sharedfolders/docker/gitea/backup.sh
# 自动备份时使用以下命令
# /bin/bash /sharedfolders/docker/docker-compose-projects/gitea/backup.sh
backup_path="/sharedfolders/git/gitea"
backup_filename=$(date "+gitea-backup-%Y%m%d_%H%M%S")
# if sudo -n uptime 2>&1 | grep -q "load"; then
# echo "请用root权限运行"
# exit 1
# fi
backup_time=$(date "+%Y%m%d_%H%M%S")
cd $(dirname ${BASH_SOURCE:-$0})
# cid=$(docker-compose ps -q gitea)
# if [ ${#cid} -gt 0 ]; then
# docker-compose up -d
# cid=$(docker-compose ps -q gitea)
# if [ ${#cid} -gt 0 ]; then
# exit
# fi
# fi
# cd data
echo "备份到 ${backup_path}/${backup_filename}.zip ..."
# sudo tar -zcpf ${backup_path}/${backup_filename}.tgz gitea
echo "备份gitea到 ${backup_path}/gitea-backup-${backup_time}.zip ..."
cid=$(docker-compose ps -q gitea)
docker-compose exec -u git gitea sh -c "/app/gitea/gitea dump -V -f /data/gitea/${backup_filename}.zip"
docker cp ${cid}:/data/gitea/${backup_filename}.zip ${backup_path}
sudo chown git:users ${backup_path} -R
docker-compose exec gitea sh -c "rm -f /data/gitea/${backup_filename}.zip"
echo "备份完毕."
docker-compose exec -u git gitea sh -c "/app/gitea/gitea dump -V -f /data/backup/gitea-backup-${backup_time}.zip"
# echo "启动 Gitea ..."
# cd $(dirname ${BASH_SOURCE:-$0})
# docker-compose up -d
echo "备份ssh到 ${backup_path}/gitea-ssh-${backup_time}.tgz ..."
docker-compose exec gitea sh -c "tar -zcpf /data/backup/gitea-ssh-${backup_time}.tgz data/ssh"
docker-compose exec gitea sh -c "chmod -R a+r mv/backup/"
echo "备份完毕."

View File

@ -28,6 +28,7 @@ services:
- gitea
volumes:
- ./data/gitea:/data
- /sharedfolders/git/gitea:/backup
ports:
- "3000:3000"
- "22:22"

View File

@ -3,14 +3,10 @@ backup_path="/sharedfolders/git/gitea"
cd $(dirname ${BASH_SOURCE:-$0})
cid=$(docker-compose ps -q gitea)
if [ ${#cid} -gt 0 ]; then
docker-compose down
fi
# 恢复备份
PS3="请选择恢复的备份: "
menu=$(ls -1 ${backup_path} | grep "gitea-backup")
menu=$(ls -1 ${backup_path} | sed -n 's/gitea-backup-\([0-9]\{8\}_[0-9]\{6\}\)\.zip/\1/g p' )
select dump_filename in ${menu} "退出"
do
@ -32,9 +28,15 @@ case $answer in
Y|y)
echo
echo "恢复备份 \"${dump_filename}\" 中 ..."
cid=$(docker-compose ps -q gitea)
if [ ${#cid} -gt 0 ]; then
docker-compose down
fi
mkdir -p ./data
docker-compose up -d
cd data
sudo mv gitea $(date "+gitea%Y%m%d_%H%M%S")
docker-compose exec gitea sh -c "mv /data/gitea /data/$(date '+gitea_%Y%m%d_%H%M%S.bak')"
sudo tar -zxf ${backup_path}/${dump_filename}
echo "恢复完毕."
echo "启动 Gitea ..."