From 6b7135eb33acbcbc3bb9502766452ac148316c72 Mon Sep 17 00:00:00 2001 From: chinky Date: Sun, 8 Jul 2018 21:17:44 +0800 Subject: [PATCH 01/12] init --- .gitignore | 2 ++ docker-compose.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34ae24e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/data +/.vscode \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0e249d5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: "2" + +networks: + gitea: + external: false + +services: + server: + image: gitea/gitea:latest + environment: + - USER_UID=1002 + - USER_GID=100 + - DB_TYPE=mysql + - DB_HOST='db:3306' + - DB_NAME='giteat' + - DB_USER='root' + - DB_PASSWD=''gitea894231'' + restart: always + networks: + - gitea + volumes: + - ./data/gitea:/data + ports: + - "3000:3000" + - "1022:22" + depends_on: + - db + + db: + image: mariadb:10 + restart: always + environment: + - MYSQL_ROOT_PASSWORD='gitea894231' + - MYSQL_USER=gitea + - MYSQL_PASSWORD=gitea + - MYSQL_DATABASE=gitea + networks: + - gitea + volumes: + - ./data/db:/var/lib/mysql \ No newline at end of file From 5d37dcbd1bb7b6ea5c3ea02c3212f96d2f1312a9 Mon Sep 17 00:00:00 2001 From: tongji Date: Sun, 8 Jul 2018 21:22:06 +0800 Subject: [PATCH 02/12] --end --- .gitignore | 0 docker-compose.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 docker-compose.yml diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 From e2689f149afa145fff71d7c7bb757f83e9ae1936 Mon Sep 17 00:00:00 2001 From: chinky Date: Sun, 8 Jul 2018 23:01:39 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 0 docker-compose.yml | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100755 new mode 100644 index 0e249d5..99f0add --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,13 +8,20 @@ services: server: image: gitea/gitea:latest environment: - - USER_UID=1002 + - 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=mysql - DB_HOST='db:3306' - - DB_NAME='giteat' + - DB_NAME='gitea' - DB_USER='root' - - DB_PASSWD=''gitea894231'' + - DB_PASSWD=gitea894231 + - TZ=Asia/Shanghai restart: always networks: - gitea @@ -30,10 +37,11 @@ services: image: mariadb:10 restart: always environment: - - MYSQL_ROOT_PASSWORD='gitea894231' + - MYSQL_ROOT_PASSWORD=gitea894231 - MYSQL_USER=gitea - - MYSQL_PASSWORD=gitea + - MYSQL_PASSWORD=gitea894231 - MYSQL_DATABASE=gitea + - TZ=Asia/Shanghai networks: - gitea volumes: From 9752d6a13a0d16572344f574028fa1706d8fdac8 Mon Sep 17 00:00:00 2001 From: tongji Date: Sun, 8 Jul 2018 23:02:24 +0800 Subject: [PATCH 04/12] --end --- .gitignore | 0 docker-compose.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 docker-compose.yml diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/docker-compose.yml b/docker-compose.yml old mode 100644 new mode 100755 From 90ab9918cf97e7a87edcc2af0c45905e2bb71c33 Mon Sep 17 00:00:00 2001 From: docker <> Date: Sun, 8 Jul 2018 23:11:18 +0800 Subject: [PATCH 05/12] Initial commit --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..bb4a2ef --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# gitea + From 9cf671eac7ca3b90deaaa5f9d6b7074e508c2a9e Mon Sep 17 00:00:00 2001 From: chinky Date: Mon, 9 Jul 2018 08:30:25 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 99f0add..cc8429f 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: image: gitea/gitea:latest environment: - APP_NAME='通技的 gitea 服务器' - - RUN_MODE='prod' + # - RUN_MODE='prod' # - SSH_DOMAIN='dgtongji.f3322.net' # - SSH_PORT=22 # - HTTP_PORT=3000 @@ -17,9 +17,9 @@ services: - USER_UID=2001 - USER_GID=100 - DB_TYPE=mysql - - DB_HOST='db:3306' - - DB_NAME='gitea' - - DB_USER='root' + - DB_HOST=db:3306 + - DB_NAME=gitea + - DB_USER=root - DB_PASSWD=gitea894231 - TZ=Asia/Shanghai restart: always @@ -27,9 +27,10 @@ services: - gitea volumes: - ./data/gitea:/data + - ./data/backup:/backup ports: - "3000:3000" - - "1022:22" + - "22:22" depends_on: - db From b3af48ab9580fbe1fcb1c42c51c93513186858dd Mon Sep 17 00:00:00 2001 From: chinky Date: Mon, 9 Jul 2018 09:26:22 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0backup.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.sh | 15 +++++++++++++++ docker-compose.yml | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 backup.sh diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..d86d6dc --- /dev/null +++ b/backup.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# 自动备份时使用以下命令 +# /bin/bash /srv/dev-disk-by-label-hd2/docker/gitea/backup.sh + +cd $(dirname ${BASH_SOURCE:-$0}) + +cid=$(docker-compose ps -q gitea) +if [ ${#cid} -gt 0 ]; then + echo "Backuping applications ..." + docker-compose exec -T gitea /bin/bash -c "cd /app/gitea/backup; su git -c \"gitea dump\"" + exit 0 +else + echo "The container \"gitea\" not running. Please start container \"gitea\"" + exit 1 +fi \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index cc8429f..e03bbc1 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ networks: external: false services: - server: + gitea: image: gitea/gitea:latest environment: - APP_NAME='通技的 gitea 服务器' @@ -27,7 +27,7 @@ services: - gitea volumes: - ./data/gitea:/data - - ./data/backup:/backup + - ./data/backup:/app/gitea/backup ports: - "3000:3000" - "22:22" From 818d60d495f04736baa89361563c83e236174f1a Mon Sep 17 00:00:00 2001 From: chinky Date: Mon, 9 Jul 2018 15:27:49 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E6=94=B9=E7=94=A8sqlite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 46 ++++++++++++++++++++++++---------------------- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bb4a2ef..bb11f52 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,44 @@ # gitea +##备份与恢复 +Gitea 已经实现了 dump 命令可以用来备份所有需要的文件到一个zip压缩文件。该压缩文件可以被用来进行数据恢复。 + +###备份命令 (dump) +先转到git用户的权限: `su git`. 再Gitea目录运行 `./gitea dump`。一般会显示类似如下的输出: + +``` +2016/12/27 22:32:09 Creating tmp work dir: /tmp/gitea-dump-417443001 +2016/12/27 22:32:09 Dumping local repositories.../home/git/gitea-repositories +2016/12/27 22:32:22 Dumping database... +2016/12/27 22:32:22 Packing dump files... +2016/12/27 22:32:34 Removing tmp work dir: /tmp/gitea-dump-417443001 +2016/12/27 22:32:34 Finish dumping in file gitea-dump-1482906742.zip +``` + +最后生成的 `gitea-dump-1482906742.zip` 文件将会包含如下内容: + +* custom - 所有保存在 custom/ 目录下的配置和自定义的文件。 +* data - 数据目录下的所有内容不包含使用文件session的文件。该目录包含 attachments, avatars, lfs, indexers, 如果使用sqlite 还会包含 sqlite 数据库文件。 +* gitea-db.sql - 数据库dump出来的 SQL。 +* gitea-repo.zip - Git仓库压缩文件。 +* log/ - Logs文件,如果用作迁移不是必须的。 +中间备份文件将会在临时目录进行创建,如果您要重新指定临时目录,可以用 +* --tempdir 参数,或者用 TMPDIR 环境变量。 + +###Restore Command (restore) +当前还没有恢复命令,恢复需要人工进行。主要是把文件和数据库进行恢复。 + +例如: + +```shell +apt-get install gitea +unzip gitea-dump-1482906742.zip +cd gitea-dump-1482906742 +mv custom/conf/app.ini /etc/gitea/conf/app.ini +unzip gitea-repo.zip +mv gitea-repo/* /var/lib/gitea/repositories/ +chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/ +mysql -u$USER -p$PASS $DATABASE Date: Mon, 9 Jul 2018 16:54:17 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20backup.sh;=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0restore.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.sh | 28 +++++++++++++++++++-------- docker-compose.yml | 2 -- lsbak.sh | 2 ++ restore.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 lsbak.sh create mode 100644 restore.sh diff --git a/backup.sh b/backup.sh index d86d6dc..9555486 100644 --- a/backup.sh +++ b/backup.sh @@ -1,15 +1,27 @@ #!/bin/bash -# 自动备份时使用以下命令 +# 自动备份时使用以下命令,需要root权限 # /bin/bash /srv/dev-disk-by-label-hd2/docker/gitea/backup.sh +backup_path="/sharedfolders/git/gitea" +backup_filename=$(date "+gitea-backup-%Y%m%d%H%M%S.tgz") + +# 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 - echo "Backuping applications ..." - docker-compose exec -T gitea /bin/bash -c "cd /app/gitea/backup; su git -c \"gitea dump\"" - exit 0 -else - echo "The container \"gitea\" not running. Please start container \"gitea\"" - exit 1 -fi \ No newline at end of file + docker-compose down +fi + +cd data +echo "备份到 ${backup_path}/${backup_filename} ..." +sudo tar -zcpf ${backup_path}/${backup_filename} gitea +sudo chown git:users ${backup_path} -R +echo "备份完毕." +cd .. +echo "启动 Gitea ..." +docker-compose up -d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index aeab350..3d0c8b6 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,8 +28,6 @@ services: - gitea volumes: - /data/gitea:/data - # - ./data/gitea/git:/data/git - # - ./data/backup:/app/gitea/backup ports: - "3000:3000" - "22:22" diff --git a/lsbak.sh b/lsbak.sh new file mode 100644 index 0000000..0976634 --- /dev/null +++ b/lsbak.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo ls /sharedfolders/git/gitea -lh diff --git a/restore.sh b/restore.sh new file mode 100644 index 0000000..dd8505c --- /dev/null +++ b/restore.sh @@ -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 From b90b0732403ca8d9b352d7edf4bfeea6827ef491 Mon Sep 17 00:00:00 2001 From: chinky Date: Mon, 9 Jul 2018 17:19:03 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9data=20=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.sh | 3 ++- docker-compose.yml | 2 +- restore.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/backup.sh b/backup.sh index 9555486..242a8b7 100644 --- a/backup.sh +++ b/backup.sh @@ -22,6 +22,7 @@ echo "备份到 ${backup_path}/${backup_filename} ..." sudo tar -zcpf ${backup_path}/${backup_filename} gitea sudo chown git:users ${backup_path} -R echo "备份完毕." -cd .. + echo "启动 Gitea ..." +cd $(dirname ${BASH_SOURCE:-$0}) docker-compose up -d \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 3d0c8b6..31b66fc 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: networks: - gitea volumes: - - /data/gitea:/data + - ./data/gitea:/data ports: - "3000:3000" - "22:22" diff --git a/restore.sh b/restore.sh index dd8505c..4a962e4 100644 --- a/restore.sh +++ b/restore.sh @@ -34,7 +34,7 @@ case $answer in echo "恢复备份 \"${dump_filename}\" 中 ..." mkdir -p ./data cd data - sudo mv gitea $(date "+gitea.%Y%m%d%H%M%S") + sudo mv gitea $(date "+gitea%Y%m%d%H%M%S") sudo tar -zxf ${backup_path}/${dump_filename} echo "恢复完毕." echo "启动 Gitea ..." From 41224d5904cf06616e73904cf864995b0dd2f887 Mon Sep 17 00:00:00 2001 From: tongji Date: Mon, 9 Jul 2018 17:32:59 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=9B=B4=E6=96=B0README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 53 ++++++++++++++--------------------------------------- backup.sh | 2 +- lsbak.sh | 0 restore.sh | 0 4 files changed, 15 insertions(+), 40 deletions(-) mode change 100644 => 100755 backup.sh mode change 100644 => 100755 lsbak.sh mode change 100644 => 100755 restore.sh diff --git a/README.md b/README.md index bb11f52..3fe4555 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,19 @@ # gitea -##备份与恢复 -Gitea 已经实现了 dump 命令可以用来备份所有需要的文件到一个zip压缩文件。该压缩文件可以被用来进行数据恢复。 - -###备份命令 (dump) -先转到git用户的权限: `su git`. 再Gitea目录运行 `./gitea dump`。一般会显示类似如下的输出: - -``` -2016/12/27 22:32:09 Creating tmp work dir: /tmp/gitea-dump-417443001 -2016/12/27 22:32:09 Dumping local repositories.../home/git/gitea-repositories -2016/12/27 22:32:22 Dumping database... -2016/12/27 22:32:22 Packing dump files... -2016/12/27 22:32:34 Removing tmp work dir: /tmp/gitea-dump-417443001 -2016/12/27 22:32:34 Finish dumping in file gitea-dump-1482906742.zip -``` - -最后生成的 `gitea-dump-1482906742.zip` 文件将会包含如下内容: - -* custom - 所有保存在 custom/ 目录下的配置和自定义的文件。 -* data - 数据目录下的所有内容不包含使用文件session的文件。该目录包含 attachments, avatars, lfs, indexers, 如果使用sqlite 还会包含 sqlite 数据库文件。 -* gitea-db.sql - 数据库dump出来的 SQL。 -* gitea-repo.zip - Git仓库压缩文件。 -* log/ - Logs文件,如果用作迁移不是必须的。 -中间备份文件将会在临时目录进行创建,如果您要重新指定临时目录,可以用 -* --tempdir 参数,或者用 TMPDIR 环境变量。 - -###Restore Command (restore) -当前还没有恢复命令,恢复需要人工进行。主要是把文件和数据库进行恢复。 - -例如: +## 备份 ```shell -apt-get install gitea -unzip gitea-dump-1482906742.zip -cd gitea-dump-1482906742 -mv custom/conf/app.ini /etc/gitea/conf/app.ini -unzip gitea-repo.zip -mv gitea-repo/* /var/lib/gitea/repositories/ -chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/ -mysql -u$USER -p$PASS $DATABASE Date: Tue, 10 Jul 2018 09:28:06 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.sh | 2 +- restore.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backup.sh b/backup.sh index 82f8818..8684443 100755 --- a/backup.sh +++ b/backup.sh @@ -3,7 +3,7 @@ # /bin/bash /sharedfolders/docker/gitea/backup.sh backup_path="/sharedfolders/git/gitea" -backup_filename=$(date "+gitea-backup-%Y%m%d%H%M%S.tgz") +backup_filename=$(date "+gitea-backup-%Y%m%d_%H%M%S.tgz") # if sudo -n uptime 2>&1 | grep -q "load"; then # echo "请用root权限运行" diff --git a/restore.sh b/restore.sh index 4a962e4..5d79da1 100755 --- a/restore.sh +++ b/restore.sh @@ -34,7 +34,7 @@ case $answer in echo "恢复备份 \"${dump_filename}\" 中 ..." mkdir -p ./data cd data - sudo mv gitea $(date "+gitea%Y%m%d%H%M%S") + sudo mv gitea $(date "+gitea%Y%m%d_%H%M%S") sudo tar -zxf ${backup_path}/${dump_filename} echo "恢复完毕." echo "启动 Gitea ..."