修改恢复脚本

This commit is contained in:
chinky 2020-01-31 15:24:20 +08:00
parent 4824209201
commit 2fbd0abbc1
3 changed files with 53 additions and 40 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
# 自动备份时使用以下命令
# /bin/bash /sharedfolders/docker/gitea/backup.sh
# /bin/bash /sharedfolders/docker/dco_project/gitea/backup.sh
backup_path="/backup"
backup_filename=${backup_path}/$(date "+gitea-backup-%Y%m%d_%H%M%S")

View File

@ -1,8 +1,11 @@
version: "2"
networks:
gitea:
external: false
# networks:
# gitea:
# driver: macvlan
# ipam:
# config:
# - subnet: 192.168.8.0/24
services:
gitea:
@ -12,7 +15,7 @@ services:
# - RUN_MODE='prod'
# - SSH_DOMAIN='dgtongji.f3322.net'
# - SSH_PORT=22
# - HTTP_PORT=3000
# - HTTP_PORT=80
# - ROOT_URL=dgtongji.f3322.net
- USER_UID=2001
- USER_GID=100
@ -24,8 +27,10 @@ services:
# - DB_PASSWD=gitea894231
- TZ=Asia/Shanghai
restart: always
networks:
- gitea
network_mode: "bridge"
# networks:
# - gitea
# ipv4_address: 192.168.8.30
volumes:
- ./data/gitea:/data
- /sharedfolders/git/gitea:/backup

View File

@ -1,12 +1,16 @@
#!/bin/bash
backup_path="/sharedfolders/git/gitea"
cd $(dirname ${BASH_SOURCE:-$0})
backup_path_docker="/backup"
backup_filename=${backup_path_docker}/$(date "+gitea-backup-%Y%m%d_%H%M%S")
cd $(dirname $0)
# ls -1 ${backup_path}
# 恢复备份
PS3="请选择恢复的备份: "
menu=$(ls -1 ${backup_path} | sed -n 's/gitea-backup-\([0-9]\{8\}_[0-9]\{6\}\)\.zip/\1/g p' )
menu=$(ls -1 ${backup_path} | sed -n 's/gitea-backup-\(20[0-9]\{6\}_[0-9]\{6\}\)\.tgz/\1/g p' )
select dump_filename in ${menu} "退出"
do
@ -22,24 +26,28 @@ do
fi
done
dump_filename="gitea-backup-${dump_filename}.tgz"
read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer
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
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}
docker-compose run --rm gitea sh -c "/app/gitea/gitea -v >/data/gitea/version.txt &&cd /data &&sqlite3 /data/gitea/gitea.db .dump >/data/gitea/gitea.sql&&echo "备份当前文件到 ${backup_filename}.tgz &&tar -zcpf ${backup_filename}.tgz ssh gitea git && chown git:users /backup -R && chmod -R a+r ${backup_path_docker}/* && rm -rf /data/* && echo "恢复备份 ${dump_filename} ..." && tar -zxf ${backup_path_docker}/${dump_filename} "
# mkdir -p ./data
# docker-compose up -d
# cd /data
# docker-compose -rm run gitea sh -c "mv /data/gitea /data/$(date '+gitea_%Y%m%d_%H%M%S.bak')"
# echo "解压文件..."
# sudo tar -zxf ${backup_path}/${dump_filename}
echo "恢复完毕."
echo "启动 Gitea ..."
# cd $(dirname ${BASH_SOURCE:-$0})
docker-compose up -d
;;
*)