Gogs 迁移

使用-h 命令查看具体参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
git@ubuntu:~/gogs$ ./gogs -h
NAME:
Gogs - A painless self-hosted Git service

USAGE:
gogs [global options] command [command options] [arguments...]

VERSION:
0.11.43.0330

COMMANDS:
web Start web server
serv This command should only be called by SSH shell
hook Delegate commands to corresponding Git hooks
cert Generate self-signed certificate
admin Perform admin operations on command line
import Import portable data as local Gogs data
backup Backup files and database
restore Restore files and database from backup
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version

备份

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
git@ubuntu:~/gogs$ ./gogs backup -h
NAME:
gogs backup - Backup files and database

USAGE:
gogs backup [command options] [arguments...]

DESCRIPTION:
Backup dumps and compresses all related files and database into zip file,
which can be used for migrating Gogs to another server. The output format is meant to be
portable among all supported database engines.

OPTIONS:
--config value, -c value Custom configuration file path (default: "custom/conf/app.ini")
--verbose, -v Show process details
--tempdir value, -t value Temporary directory path (default: "/tmp")
--target value Target directory path to save backup archive (default: "./")
--archive-name value Name of backup archive (default: "gogs-backup-20180522084558.zip")
--database-only Only dump database
--exclude-repos Exclude repositories

如果仓库超过1GB那最好不要使用该命令来备份迁移,直接将数据库导出,仓库打包迁移.

1
2
3
4
5
./gogs backup --exclude-repos #备份、除了仓库

./gogs backup --config=my/custom/conf/app.ini # 如果自定义配置文件不在默认路径

./gogs backup --database-only # 仅备份数据库

恢复

将备份文件gogs-backup-xxxx.zip上传到新服务器,在新服务器安装Gogs.

  • 创建对应 git 用户
  • 创建对应 Mysql 数据库

Gogs运行用户尽量与之前运行用户同名,否则在导入过程中会出现使用原来用户无权限的情况!

1
2
3
4
./gogs restore -h  #查看帮助手册

# 使用自定义新配置文件(如新环境数据库信息修改,则需要此option)
./gogs restore --config=my/custom/conf/app.ini --from="/home/git/gogs-backup-xxxx.zip"

注意事项

在恢复过程中如果遇到 /tmp/gogs-backup 无权限情况,则说明当前登录用户不是原git用户,可以将/tmp/gogs-backup文件删除,切换用户
从新执行命令.

如果新系统临时文件路径为/opt/则也会出现无法找到/tmp/invalid cross-device link错误.
解决办法:使用--tempdir /opt/gogs/tmp --target /opt/gogs_bak/ 指定备份临时目录。

遇到数据库无权限情况,确定是否正确生成对应的用户,并且赋值正确权限.且需要注意数据库用户的访问来源!
localhost127.0.0.1的来源是不一样的。每个来源都有各自的密码!Gogs默认使用127.0.0.1链接数据库,如果创建的用户使用localhost方式链接,
并赋权,则会在导入过程中出现Access Denied From user ....
解决办法:对该数据库用户的127.0.0.1的链接方式修改与localhost方式一样的密码!

参考

参考链接