修改恢复脚本
This commit is contained in:
parent
4824209201
commit
2fbd0abbc1
|
@ -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")
|
||||
|
|
|
@ -1,37 +1,42 @@
|
|||
version: "2"
|
||||
|
||||
networks:
|
||||
gitea:
|
||||
external: false
|
||||
# networks:
|
||||
# gitea:
|
||||
# driver: macvlan
|
||||
# ipam:
|
||||
# config:
|
||||
# - subnet: 192.168.8.0/24
|
||||
|
||||
services:
|
||||
gitea:
|
||||
image: gitea/gitea:latest
|
||||
environment:
|
||||
- APP_NAME='通技的 gitea 服务器'
|
||||
# - RUN_MODE='prod'
|
||||
# - SSH_DOMAIN='dgtongji.f3322.net'
|
||||
# - SSH_PORT=22
|
||||
# - HTTP_PORT=3000
|
||||
# - ROOT_URL=dgtongji.f3322.net
|
||||
- USER_UID=2001
|
||||
- USER_GID=100
|
||||
- DB_TYPE=sqlite3
|
||||
# - DB_TYPE=mysql
|
||||
# - DB_HOST=db:3306
|
||||
# - DB_NAME=gitea
|
||||
# - DB_USER=root
|
||||
# - DB_PASSWD=gitea894231
|
||||
- TZ=Asia/Shanghai
|
||||
restart: always
|
||||
networks:
|
||||
- gitea
|
||||
volumes:
|
||||
- ./data/gitea:/data
|
||||
- /sharedfolders/git/gitea:/backup
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "22:22"
|
||||
gitea:
|
||||
image: gitea/gitea:latest
|
||||
environment:
|
||||
- APP_NAME='通技的 gitea 服务器'
|
||||
# - RUN_MODE='prod'
|
||||
# - SSH_DOMAIN='dgtongji.f3322.net'
|
||||
# - SSH_PORT=22
|
||||
# - HTTP_PORT=80
|
||||
# - ROOT_URL=dgtongji.f3322.net
|
||||
- USER_UID=2001
|
||||
- USER_GID=100
|
||||
- DB_TYPE=sqlite3
|
||||
# - DB_TYPE=mysql
|
||||
# - DB_HOST=db:3306
|
||||
# - DB_NAME=gitea
|
||||
# - DB_USER=root
|
||||
# - DB_PASSWD=gitea894231
|
||||
- TZ=Asia/Shanghai
|
||||
restart: always
|
||||
network_mode: "bridge"
|
||||
# networks:
|
||||
# - gitea:
|
||||
# ipv4_address: 192.168.8.30
|
||||
volumes:
|
||||
- ./data/gitea:/data
|
||||
- /sharedfolders/git/gitea:/backup
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "22:22"
|
||||
# depends_on:
|
||||
# - db
|
||||
|
||||
|
@ -47,4 +52,4 @@ services:
|
|||
# networks:
|
||||
# - gitea
|
||||
# volumes:
|
||||
# - ./data/db:/var/lib/mysql
|
||||
# - ./data/db:/var/lib/mysql
|
||||
|
|
24
restore.sh
24
restore.sh
|
@ -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
|
||||
;;
|
||||
*)
|
||||
|
|
Loading…
Reference in New Issue