Skip to content

Use to_boolean helper for backup force env

What does this MR do and why?

Fixes #358231 (closed)

Previously we explicitly required force=yes. Instead here we are using our Utils.to_boolean helper that accepts a few typical boolean values. This will make it more consistent with other boolean env vars.

While we could write tests to enumerate all possible values of skip I don't think it's really necessary. The fact that the tests still pass with the new boolean parser is sufficient.

How to set up and validate locally

  1. force is only used on restore. So first we need to create a backup.
    $ bundle exec rake gitlab:backup:create
    ...
    2022-04-13 10:37:53 +1200 -- Backup 1649803057_2022_04_13_14.10.0-pre is done.
  2. Restore from said backup with force set to false or nothing so we can see what happens. The prompt is what we use force to skip.
    $ bundle exec rake gitlab:backup:restore BACKUP=1649803057_2022_04_13_14.10.0-pre
    2022-04-13 10:39:35 +1200 -- Unpacking backup ... 
    2022-04-13 10:39:36 +1200 -- Unpacking backup ... done
    2022-04-13 10:39:36 +1200 -- Restoring database ... 
    2022-04-13 10:39:36 +1200 -- Be sure to stop Puma, Sidekiq, and any other process that
    connects to the database before proceeding. For Omnibus
    installs, see the following link for more information:
    https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations
    
    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)? 
  3. Restore from the backup with force set. Notice that there's no longer a prompt before restoring the database.
    $ bundle exec rake gitlab:backup:restore BACKUP=1649803057_2022_04_13_14.10.0-pre force=1
    2022-04-13 10:42:26 +1200 -- Unpacking backup ... 
    2022-04-13 10:42:27 +1200 -- Unpacking backup ... done
    2022-04-13 10:42:27 +1200 -- Restoring database ... 
    2022-04-12 22:42:27 UTC -- Cleaning the database ... 
    2022-04-12 22:42:28 UTC -- done
    Restoring PostgreSQL database gitlabhq_development ... SET
    SET
    ...

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by James Fargher

Merge request reports

Loading