修改恢复脚本

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
# 自动备份时使用以下命令 # 自动备份时使用以下命令
# /bin/bash /sharedfolders/docker/gitea/backup.sh # /bin/bash /sharedfolders/docker/dco_project/gitea/backup.sh
backup_path="/backup" backup_path="/backup"
backup_filename=${backup_path}/$(date "+gitea-backup-%Y%m%d_%H%M%S") backup_filename=${backup_path}/$(date "+gitea-backup-%Y%m%d_%H%M%S")

View File

@ -1,37 +1,42 @@
version: "2" version: "2"
networks: # networks:
gitea: # gitea:
external: false # driver: macvlan
# ipam:
# config:
# - subnet: 192.168.8.0/24
services: services:
gitea: gitea:
image: gitea/gitea:latest image: gitea/gitea:latest
environment: environment:
- APP_NAME='通技的 gitea 服务器' - APP_NAME='通技的 gitea 服务器'
# - RUN_MODE='prod' # - RUN_MODE='prod'
# - SSH_DOMAIN='dgtongji.f3322.net' # - SSH_DOMAIN='dgtongji.f3322.net'
# - SSH_PORT=22 # - SSH_PORT=22
# - HTTP_PORT=3000 # - HTTP_PORT=80
# - ROOT_URL=dgtongji.f3322.net # - ROOT_URL=dgtongji.f3322.net
- USER_UID=2001 - USER_UID=2001
- USER_GID=100 - USER_GID=100
- DB_TYPE=sqlite3 - DB_TYPE=sqlite3
# - DB_TYPE=mysql # - DB_TYPE=mysql
# - DB_HOST=db:3306 # - DB_HOST=db:3306
# - DB_NAME=gitea # - DB_NAME=gitea
# - DB_USER=root # - DB_USER=root
# - DB_PASSWD=gitea894231 # - DB_PASSWD=gitea894231
- TZ=Asia/Shanghai - TZ=Asia/Shanghai
restart: always restart: always
networks: network_mode: "bridge"
- gitea # networks:
volumes: # - gitea
- ./data/gitea:/data # ipv4_address: 192.168.8.30
- /sharedfolders/git/gitea:/backup volumes:
ports: - ./data/gitea:/data
- "3000:3000" - /sharedfolders/git/gitea:/backup
- "22:22" ports:
- "3000:3000"
- "22:22"
# depends_on: # depends_on:
# - db # - db
@ -47,4 +52,4 @@ services:
# networks: # networks:
# - gitea # - gitea
# volumes: # volumes:
# - ./data/db:/var/lib/mysql # - ./data/db:/var/lib/mysql

View File

@ -1,12 +1,16 @@
#!/bin/bash #!/bin/bash
backup_path="/sharedfolders/git/gitea" 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="请选择恢复的备份: " 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} "退出" select dump_filename in ${menu} "退出"
do do
@ -22,24 +26,28 @@ do
fi fi
done done
dump_filename="gitea-backup-${dump_filename}.tgz"
read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer
case $answer in case $answer in
Y|y) Y|y)
echo echo
echo "恢复备份 \"${dump_filename}\" 中 ..."
cid=$(docker-compose ps -q gitea) cid=$(docker-compose ps -q gitea)
if [ ${#cid} -gt 0 ]; then if [ ${#cid} -gt 0 ]; then
docker-compose down docker-compose down
fi fi
mkdir -p ./data 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} "
docker-compose up -d
cd data # mkdir -p ./data
docker-compose exec gitea sh -c "mv /data/gitea /data/$(date '+gitea_%Y%m%d_%H%M%S.bak')" # docker-compose up -d
sudo tar -zxf ${backup_path}/${dump_filename} # 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 "恢复完毕."
echo "启动 Gitea ..." echo "启动 Gitea ..."
# cd $(dirname ${BASH_SOURCE:-$0})
docker-compose up -d docker-compose up -d
;; ;;
*) *)