This commit is contained in:
chinky 2019-06-04 16:20:18 +08:00
commit 390beb07d2
8 changed files with 2835 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/data
/.vscode
docker-compose.yml.*

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# gitea
## 备份
```shell
/bin/bash /sharedfolders/docker/gitea/backup.sh
```
## 恢复
```shell
./restore.sh
```
## 列出备份文件
```shell
./lsbak.sh
```

33
backup.sh Normal file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# 自动备份时使用以下命令,需要root权限
# /bin/bash /sharedfolders/docker/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
cd $(dirname ${BASH_SOURCE:-$0})
cid=$(docker-compose ps -q gitea)
if [ ${#cid} -gt 0 ]; then
docker-compose up -d
if [ ${#cid} -gt 0 ]; then
exit
fi
fi
# cd data
echo "备份到 ${backup_path}/${backup_filename} ..."
# sudo tar -zcpf ${backup_path}/${backup_filename}.tgz gitea
docker-compose exec -u git gitea sh -c '/app/gitea/gitea dump -f /data/gitea/${backup_filename}.zip'
docker cp $(docker ps -qf "name=gitea"):/data/gitea/${backup_filename}.zip ${backup_path}
sudo chown git:users ${backup_path} -R
echo "备份完毕."
# echo "启动 Gitea ..."
# cd $(dirname ${BASH_SOURCE:-$0})
# docker-compose up -d

49
docker-compose.yml Normal file
View File

@ -0,0 +1,49 @@
version: "2"
networks:
gitea:
external: false
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
ports:
- "3000:3000"
- "22:22"
# depends_on:
# - db
# db:
# image: mariadb:10
# restart: always
# environment:
# - MYSQL_ROOT_PASSWORD=gitea894231
# - MYSQL_USER=gitea
# - MYSQL_PASSWORD=gitea894231
# - MYSQL_DATABASE=gitea
# - TZ=Asia/Shanghai
# networks:
# - gitea
# volumes:
# - ./data/db:/var/lib/mysql

BIN
gitea.db Normal file

Binary file not shown.

2682
gitea.sql Normal file

File diff suppressed because it is too large Load Diff

2
lsbak.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
sudo ls /sharedfolders/git/gitea -lh

47
restore.sh Normal file
View File

@ -0,0 +1,47 @@
#!/bin/bash
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")
select dump_filename in ${menu} "退出"
do
if [ -n "${dump_filename}" ]; then
case "${dump_filename}" in
"退出")
exit 1
;;
*)
break
;;
esac
fi
done
read -n1 -p "恢复备份 : ${dump_filename} (N/y)? : " answer
case $answer in
Y|y)
echo
echo "恢复备份 \"${dump_filename}\" 中 ..."
mkdir -p ./data
cd data
sudo mv gitea $(date "+gitea%Y%m%d_%H%M%S")
sudo tar -zxf ${backup_path}/${dump_filename}
echo "恢复完毕."
echo "启动 Gitea ..."
docker-compose up -d
;;
*)
echo
exit 1
;;
esac