GitLab提供的恢复命令需要手动输入yes或no决定选择,这需要使用者手动执行,如果有特定需要希望略去手动输入选择的场景,可以考虑使用HereDocument传入选择进行非交互方式的恢复,另外还可以通过指定force值为yes进行非交互式数据恢复。
环境准备具体可参看:https://liumiaocn.blog.csdn.net/article/details/107950120
手动恢复手动恢复需要手动输入yes,在这个过程中手动输入了多次yes,执行示例日志如下所示:
# gitlab-rake gitlab:backup:restore BACKUP=1597188417 Unpacking backup ... done Before restoring the database, we will remove all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. Do you want to continue (yes/no)? yes Removing all tables. Press `Ctrl-C` within 5 seconds to abort 2020-08-12 02:27:25 +0000 -- Cleaning the database ... 2020-08-12 02:27:34 +0000 -- done 2020-08-12 02:27:34 +0000 -- Restoring database ... Restoring PostgreSQL database gitlabhq_production ... SET SET SET SET SET set_config ------------ (1 row) SET SET SET SET ERROR: relation "public.u2f_registrations" does not exist ERROR: relation "public.timelogs" does not exist ...省略 ALTER TABLE [DONE] 2020-08-12 02:28:19 +0000 -- done 2020-08-12 02:28:19 +0000 -- Restoring repositories ... * root/testproject ... [DONE] 2020-08-12 02:28:20 +0000 -- done 2020-08-12 02:28:20 +0000 -- Restoring uploads ... 2020-08-12 02:28:20 +0000 -- done 2020-08-12 02:28:20 +0000 -- Restoring builds ... 2020-08-12 02:28:20 +0000 -- done 2020-08-12 02:28:20 +0000 -- Restoring artifacts ... 2020-08-12 02:28:20 +0000 -- done 2020-08-12 02:28:20 +0000 -- Restoring pages ... 2020-08-12 02:28:20 +0000 -- done 2020-08-12 02:28:20 +0000 -- Restoring lfs objects ... 2020-08-12 02:28:20 +0000 -- done 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. #
上述日志显示不全,实际上在执行的时候出现了如下几次需要选择的交互
- 提示会删除既有数据,有所影响,尤其是有自定义的表的情况下,需要用户确认是否确实要执行
Unpacking backup ... done Before restoring the database, we will remove all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. Do you want to continue (yes/no)? yes
- 重建ssh key的信息,会失去之前存在authorized_keys的内容,进行是否继续的提示
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)?GitLab相关讨论
如下相关讨论提到此问题,但是未给出方法:
- https://forum.gitlab.com/t/suppress-gitlab-backup-restore-prompt/35951/2
但实际查看最新的问题提到了force选项,在GitLab备份恢复总结的文章中也有。
方式1: HereDocument方式经确认和验证,发现restore接受HereDocument的方式,比如上述恢复可使用如下方式即可
# gitlab-rake gitlab:backup:restore BACKUP=1597188417yes > EOF
执行示例如下所示:
# gitlab-rake gitlab:backup:restore BACKUP=1597188417yes > EOF Unpacking backup ... done Before restoring the database, we will remove all existing tables to avoid future upgrade problems. Be aware that if you have custom tables in the GitLab database these tables and all data will be removed. Do you want to continue (yes/no)? Removing all tables. Press `Ctrl-C` within 5 seconds to abort 2020-08-12 06:34:29 +0000 -- Cleaning the database ... 2020-08-12 06:34:35 +0000 -- done 2020-08-12 06:34:35 +0000 -- Restoring database ... Restoring PostgreSQL database gitlabhq_production ... SET SET SET SET SET set_config ------------ (1 row) SET SET SET SET ERROR: relation "public.u2f_registrations" does not exist ERROR: relation "public.timelogs" does not exist ...省略 ALTER TABLE ALTER TABLE ALTER TABLE [DONE] 2020-08-12 06:34:53 +0000 -- done 2020-08-12 06:34:53 +0000 -- Restoring repositories ... * root/testproject ... [DONE] 2020-08-12 06:34:54 +0000 -- done 2020-08-12 06:34:54 +0000 -- Restoring uploads ... 2020-08-12 06:34:54 +0000 -- done 2020-08-12 06:34:54 +0000 -- Restoring builds ... 2020-08-12 06:34:54 +0000 -- done 2020-08-12 06:34:54 +0000 -- Restoring artifacts ... 2020-08-12 06:34:54 +0000 -- done 2020-08-12 06:34:54 +0000 -- Restoring pages ... 2020-08-12 06:34:54 +0000 -- done 2020-08-12 06:34:54 +0000 -- Restoring lfs objects ... 2020-08-12 06:34:54 +0000 -- done 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)? 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. #方式2: 使用force选项
执行示例命令:gitlab-backup restore force=yes BACKUP=1597812374_2020_08_19_12.10.5
# gitlab-backup restore force=yes BACKUP=1597812374_2020_08_19_12.10.5 Unpacking backup ... done 2020-08-19 08:01:23 +0000 -- Cleaning the database ... 2020-08-19 08:01:25 +0000 -- done 2020-08-19 08:01:25 +0000 -- Restoring database ... Restoring PostgreSQL database gitlabhq_production ... SET SET SET SET SET set_config ------------ (1 row) SET SET SET SET ERROR: relation "public.u2f_registrations" does not exist ERROR: relation "public.timelogs" does not exist ...省略 ALTER TABLE ALTER TABLE [DONE] 2020-08-19 08:01:37 +0000 -- done 2020-08-19 08:01:37 +0000 -- Restoring repositories ... * root/webhookproject ... [DONE] 2020-08-19 08:01:38 +0000 -- done 2020-08-19 08:01:38 +0000 -- Restoring uploads ... 2020-08-19 08:01:38 +0000 -- done 2020-08-19 08:01:38 +0000 -- Restoring builds ... 2020-08-19 08:01:38 +0000 -- done 2020-08-19 08:01:38 +0000 -- Restoring artifacts ... 2020-08-19 08:01:38 +0000 -- done 2020-08-19 08:01:38 +0000 -- Restoring pages ... 2020-08-19 08:01:38 +0000 -- done 2020-08-19 08:01:38 +0000 -- Restoring lfs objects ... 2020-08-19 08:01:38 +0000 -- done 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. #