Skip to content
Snippets Groups Projects

Add rake task for copying 'main' database to 'ci' database

1 unresolved thread
2 files
+ 28
30
Compare changes
  • Side-by-side
  • Inline
Files
2
#!/usr/bin/env bash
function update_gitlab_config() {
gitlab_config="# Added by decomposed migration script: `date`
gitlab_rails['env'] = { 'GITLAB_ALLOW_SEPARATE_CI_DATABASE' => 'true' }
function generate_gitlab_config() {
gitlab_config="gitlab_rails['env'] = { 'GITLAB_ALLOW_SEPARATE_CI_DATABASE' => 'true' }
gitlab_rails['databases']['ci']['enable'] = true
gitlab_rails['databases']['ci']['db_database'] = 'gitlabhq_production_ci'"
@@ -47,10 +46,9 @@ gitlab_rails['databases']['ci']['db_database'] = 'gitlabhq_production_ci'"
gitlab_config=$(printf "${gitlab_config}\ngitlab_rails['databases']['ci']['db_sslcompression']= '"$GITLAB_BACKUP_CI_PGSSLCOMPRESSION"'")
fi
echo "$gitlab_config" >> /etc/gitlab/gitlab.rb
echo "$gitlab_config"
}
if [ "$(id -u)" -ne 0 ]
then
echo "Please run as root." >&2
@@ -72,11 +70,6 @@ What this script will do:
See https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#enable-or-disable-background-migrations
- Stop the Gitlab Instance except PostgreSQL
- Copy data in gitlabhq_production to gitlabhq_production_ci (by dumping, then restoring)
- Modify /etc/gitlab/gitlab.rb and create a backup of the original configuration
- Generate new configuration files using 'gitlab-ctl reconfigure'
- Enable table-level writes locks that prevent 'main' data to be written to 'ci' and the other way around
See https://docs.gitlab.com/ee/development/database/multiple_databases.html#locking-writes-on-the-tables-that-dont-belong-to-the-database-schemas
- Enable background migrations
Please confirm the upgrade by pressing 'y':
EXPLANATION
@@ -122,26 +115,10 @@ then
exit 1
fi
cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.org
update_gitlab_config
gitlab-ctl reconfigure
gitlab-rake gitlab:db:lock_writes
echo "Enabling Background migrations..."
gitlab-rails runner "Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)"
cat <<- EOF
GitLab is now running on two databases. Data related to CI is now written to the ci
database.
A copy of the original configuration file has been saved in /etc/gitlab/gitlab.rb.org
You can now start the GitLab services by running 'sudo gitlab-ctl restart'
You can also remove duplicated data by running:
'sudo gitlab-rake gitlab:db:truncate_legacy_tables:main'
'sudo gitlab-rake gitlab:db:truncate_legacy_tables:ci'
First step of migration is now done: data has been copied to new database.
You should now modify the GitLab configuration file in /etc/gitlab/gitlab.rb.
When you are ready, you can start the 'post-migrate' script.
EOF
generate_gitlab_config
Loading