迁移Gogs(从Window Server 2019中迁移到CentOS7.9)


摘要:
Gogs从Window Server 2019中迁移到CentOS7.9;
CentOS中Gogs为新安装的,没有其他仓库;
CentOS中操作用户为root;


1、在window中执行备份命令


当前目录生成【gogs-backup-20210223111220.zip】类似的压缩包。

F:\ProgramFiles\windows_amd64\gogs>gogs backup
2021/02/23 11:12:20 [ INFO] Backup root directory: C:\Users\ZEQIPC~1\AppData\Local\Temp\gogs-backup-462344635
2021/02/23 11:12:20 [ INFO] Packing backup files to: gogs-backup-20210223111220.zip
2021/02/23 11:12:20 [ INFO] Dumping repositories in 'F:/ProgramFiles/windows_amd64/config/systemprofile/gogs-repositories'
2021/02/23 11:13:23 [ INFO] Repositories dumped to: C:\Users\ZEQIPC~1\AppData\Local\Temp\gogs-backup-462344635/repositories.zip
2021/02/23 11:14:13 [ INFO] Backup succeed! Archive is located at: gogs-backup-20210223111220.zip
F:\ProgramFiles\windows_amd64\gogs>

【扩展】通过 help查看backup命令使用方法(在Windows中敲的)

F:\ProgramFiles\windows_amd64\gogs>gogs backup --help
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: "C:\\Users\\ZEQIPC~1\\AppData\\Local\\Temp")
   --target value             Target directory path to save backup archive (default: "./")
   --archive-name value       Name of backup archive (default: "gogs-backup-20210223111203.zip")
   --database-only            Only dump database
   --exclude-repos            Exclude repositories
2、在CentOS中恢复备份数据


2.1、将【gogs-backup-20210223111220.zip】上传至centos系统中
2.2、开始恢复数据


相关命令

 ./gogs restore --config /usr/local/gogs/custom/conf/app.ini --tempdir  /data/tmp  --from gogs-backup-20210223111220.zip

2.3、使用CentOS中的配置文件替换恢复的配置文件(为了解决错误:User configured to run Gogs is "git", but the current user is)

[root@localhost gogs]# mv custom custom.backup
[root@localhost gogs]# mv custom.bak custom


【扩展】通过 help查看restore命令使用方法(在CentOS中敲的)

[root@localhost gogs]# ./gogs restore --help
NAME:
   gogs restore - Restore files and database from backup
USAGE:
   gogs restore [command options] [arguments...]
DESCRIPTION:
   Restore imports all related files and database from a backup archive.
The backup version must lower or equal to current Gogs version. You can also import
backup from other database engines, which is useful for database migrating.
If corresponding files or database tables are not presented in the archive, they will
be skipped and remain unchanged.
OPTIONS:
   --config value, -c value   Custom configuration file path
   --verbose, -v              Show process details
   --tempdir value, -t value  Temporary directory path (default: "/tmp")
   --from value               Path to backup archive
   --database-only            Only import database
   --exclude-repos            Exclude repositories
3、检查恢复情况


3.1、数据库中【repository】等表的数据已经恢复
3.2、仓库根目录下的数据已经恢复

4、重启访问


恢复完成,正常使用。

来源: