Skip to content

Stop validating snippets when restoring from backup

James Fargher requested to merge no_snippet_validation_on_restore into master

What does this MR do and why?

#428248 (closed)

Previously snippets have been validated when restoring a backup. This causes confusing error messages and failure of snippets that work (despite being invalid for having an incorrect branch name).

Restore should not be performing any data validation. It should instead try and restore the system as close to how it was when the backup was taken. This is a fundamental difference between importers and restoring from backups.

How to set up and validate locally

  1. Checkout master and make sure GDK is restarted etc.
    $ git checkout master
    $ gdk reconfigure && gdk restart
  2. Make sure you have a snippet created. Your Work > Snippets > New Snippet.
  3. Make sure the snippet is invalid. For our purposes it doesn't matter how exactly.
    [2] pry(main)> s = Snippet.find(21)
    => #<PersonalSnippet id:21 $21>
    [3] pry(main)> s.repository.remove
    => <Gitaly::RemoveRepositoryResponse: >
    [4] pry(main)> s.repository.create_repository
    => <Gitaly::CreateRepositoryResponse: >
    [5] pry(main)> Snippets::RepositoryValidationService.new(nil, s).execute
    => #<ServiceResponse:0x00007fc69fa221d8
     @http_status=400,
     @message="Error: Repository must contain at least 1 file.",
     @payload={},
     @reason=nil,
     @status=:error>
  4. Create a backup.
    $ bundle exec rake gitlab:backup:create
    ...
    2023-11-16 01:45:36 UTC -- Backup 1700099112_2023_11_16_16.7.0-pre is done.
  5. Try restore on master. Note that now instead of having an invalid snippet, the snippet will be removed.
    $ bundle exec rake gitlab:backup:restore BACKUP=1700099112_2023_11_16_16.7.0-pre
    ...
    Snippet snippets/21 can't be restored: Error: Repository must contain at least 1 file.
    ...
    2023-11-16 01:51:50 UTC -- Restore task is done.
  6. Change to this branch no_snippet_validation_on_restore and try restore again. Note that the snippet will now exist, but be invalid.
    $ git switch no_snippet_validation_on_restore
    $ bundle exec rake gitlab:backup:restore BACKUP=1700099112_2023_11_16_16.7.0-pre
    ...
    2023-11-16 01:54:53 UTC -- Restore task is done.

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