- 因公司更换服务器服务商,服务器迁移到另外一家服务商,今天就模拟线上迁移gitlab的操作
- git-A IP:192.168.82.184
- git-B IP:192.168.82.184
- 在做备份迁移前提是版本号一样,否则会失败.
Step 1.gitlab备份 gita-A
#创建备份
$ gitlab-rake gitlab:backup:create STRATEGY=copy
2020-03-31 04:17:23 -0400 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2020-03-31 04:17:27 -0400 -- done
2020-03-31 04:17:27 -0400 -- Dumping repositories ...
* root/tesporject (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [SKIPPED]
[SKIPPED] Wiki
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping uploads ...
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping builds ...
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping artifacts ...
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping pages ...
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping lfs objects ...
2020-03-31 04:17:28 -0400 -- done
2020-03-31 04:17:28 -0400 -- Dumping container registry images ...
2020-03-31 04:17:28 -0400 -- [DISABLED]
Creating backup archive: 1585642648_2020_03_31_12.9.1_gitlab_backup.tar ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
#备份的文件路径
$ ll /var/opt/gitlab/backups
total 160
-rw-------. 1 git git 163840 Mar 31 04:17 1585642648_2020_03_31_12.9.1_gitlab_backup.tar
Step 2.将git-A 备份/var/opt/gitlab/backups/1585642648_2020_03_31_12.9.1_gitlab_backup.tar 复制到git-B
$ scp /var/opt/gitlab/backups/1585642648_2020_03_31_12.9.1_gitlab_backup.tar root@193.168.82.185:/var/opt/gitlab/backups/
Step 3.gitlab恢复
说明:恢复前需要先停掉数据连接服务
#git-B 操作
$ gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
$ gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
1.修改权限,600没有权限恢复
$ ls -lh /var/opt/gitlab/backups/
total 160K
-rw-------. 1 root root 160K Mar 31 04:17 1585642648_2020_03_31_12.9.1_gitlab_backup.tar
$ chmod 777 /var/opt/gitlab/backups/1585642648_2020_03_31_12.9.1_gitlab_backup.tar
2.恢复
说明:会有两次需要输入yes
$ gitlab-rake gitlab:backup:restore BACKUP=1585642648_2020_03_31_12.9.1
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes
Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
and are not included in this backup. You will need to restore these files manually.
Restore task is done.
3.重启gitlab
$ gitlab-ctl start unicorn
$ gitlab-ctl start sidekiq
4.访问git-A & git-B
说明:git-A 做备份前时创建了一个项目testprojects,备份恢复到git-B数据一样.
来源:oschina
链接:https://my.oschina.net/AnnaWu/blog/3215680