GitLab: bakup and restore

WARNING: You can only restore a backup to exactly the same version of GitLab that you created it on.

    :: Create a backup of the GitLab system:

  • sudo gitlab-rake gitlab:backup:create

    the backup file will be created at /var/opt/gitlab/backups/
    or where specified in the gitlab config file.

    You can skip the backup for come components using:

    sudo gitlab-rake gitlab:backup:create SKIP=db,uploads
  • Please be informed that a backup does not store your configuration files. One reason for this is that your database contains encrypted information for two-factor authentication. Storing encrypted information along with its key in the same place defeats the purpose of using encryption in the first place!
    At the very minimum you should backup /etc/gitlab/gitlab-secrets.json (Omnibus) or /home/git/gitlab/.secret (source) to preserve your database encryption key.
    :: Restore a previously created backup:

  • We will assume that you have installed GitLab from an omnibus package and run
    sudo gitlab-ctl reconfigure

    at least once.

    Note: that you need to run gitlab-ctl reconfigure after changing gitlab-secrets.json.

    First make sure your backup tar file is in /var/opt/gitlab/backups (or wherever gitlab_rails[‘backup_path’] points to).

    sudo cp 1393513186_gitlab_backup.tar /var/opt/gitlab/backups/
  • Next, restore the backup by running the restore command. You need to specify the timestamp of the backup you are restoring.
    # Stop processes that are connected to the database
    sudo gitlab-ctl stop unicorn
    sudo gitlab-ctl stop sidekiq
    # This command will overwrite the contents of your GitLab database!
    sudo gitlab-rake gitlab:backup:restore BACKUP=1393513186
    # Start GitLab
    sudo gitlab-ctl start
    # Check GitLab
    sudo gitlab-rake gitlab:check SANITIZE=true