Implement restore subcommand of gitlab-backup-cli
What does this MR do and why?
Through the course of #427337 (closed), we pulled parts of legacy backup code in lib/backup into a new gem for the command gitlab-backup-cli. Prior to this MR, this command line is capable of creating a backup of GitLab app data via running gitlab-backup-cli backup all. It creates a non-tarred directory that contains each type of data in its own backup file, with a backup_information.json file to capture the backup context.
This MR augments the gitlab-backup-cli command with a set of restore subcommands.
Changes:
- adds these subcommands to the
gitlab-backup-clicommand: gitlab-backup-cli restore all BACKUP_IDgitlab-backup-cli restore help- The
BACKUP_IDargument refers to the base of the archive directory name as created by thebackup allcommand (usually a timestamp, date, and gitlab version like "1715018771_2024_05_06_17.0.0-pre") - Augments
Gitlab::Backup::Cli::BackupMetadatato read and cast the key-value pairs in thebackup_information.jsonfile - Defines
Gitlab::Backup::Cli::Task#restore!to perform proper data restoration for all types of task objects. As we currently do in the backup creation, we are still wrapping and reusing legacy code from./lib/backups
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- In a dev environment, run
gitlab-backup-cli backup allto create a backup. Take note of the backup id output in the last line on a successful run:
GitLab Backup finished: 1715033183_2024_05_06_17.0.0-pre (6s)
^^^^^^^ this is the id ^^^^^^^^^
- Confirm the backup exists (in dev, it will be located at
tmp/backups/$BACKUP_ID/, using the ID from above) - Go into your environment and mess around with data -- add new artifacts, repos, etc... Mess with your configuration settings. Delete some projects, groups, or issues.
- Run the new restore command as shown below. Take note of any unusual warnings or errors in the output.
gitlab-backup-cli restore all $BACKUP_ID
# replace $BACKUP_ID with the actual string from step 1 (e.g. 1715033183_2024_05_06_17.0.0-pre)
# example:
# gitlab-backup-cli restore all 1715033183_2024_05_06_17.0.0-pre
- Load up GitLab in the environment and inspect to see that it functions. None of the changes you made in step 2 should be present. It should be identical to the moment you captured the backup in step 1.
Edited by Kyle Yetter