Gitlab

How to create and retrieve your Gitlab tokens

Creating your Gitlab tokens.

Go to the Application / Manage Token page

  • Once you are logged in,
  • navigate to your user settings by clicking on your profile picture in the top-right corner of the left navigation panel. From there, select “Edit Profile”
    • Notion image
  • In the left-hand menu, click on "Access Tokens".

→ This will take you to the Access Tokens page.

 

Create a new token

  • On the Access Tokens page, click on the "Add New Token" button. This will open a new window where you can configure your new access token.
    • Notion image
  • In the "Token Name" field, enter a descriptive name for your token. This will help you identify it later.
  • Once you have configured your access token, click on the "Create personal access token" button to create it.
 

Copy your token

After you click the "Create personal access token" button, gitlab will generate a new access token for you. This token will be displayed on the screen.

Notion image

Copy your access token and store it in a safe place. You will not be able to retrieve it later.

Handling Backup Errors: 401 vs 403

When performing GitLab backups, it’s important to understand how different error codes impact the process. While a 401 Unauthorized error will halt the backup due to invalid credentials, a 403 Forbidden error generally won’t stop the process, as it only affects access to specific resources while allowing the backup to continue for others.

🚨

401 Unauthorized Error: This error occurs when the authentication credentials (such as a personal access token or API key) are invalid or missing. Since proper authentication is essential to interact with the GitLab API and access the repository data, a 401 error will cause the backup process to fail. Without valid credentials, the backup cannot proceed.

⚠️

403 Forbidden Error: This error means that the request is authenticated but the user or token does not have permission to access a specific resource (e.g., trying to access a repository you don’t have permission to read). However, in the context of a backup, if the backup agent is designed to skip inaccessible resources and continue with the rest of the data, a 403 error may not halt the backup process entirely. It will only affect the resources that are restricted, but the backup can continue with the accessible ones.

 

Restoring GitLab backups

Steps to Restore a Bare Clone:

1. Create a New Repository on GitLab:

  • Go to GitLab and create a new empty repository. Make sure to not initialize it with a README or any files (like .gitignore), as this can cause conflicts.

2. Set Up the Repository Locally:

  • On your local machine, navigate to the directory where your bare clone exists. If your bare clone is stored as myrepo.git, make sure to point to that.

3. Push the Bare Clone to GitLab:

Assuming your bare clone is in a folder named myrepo.git, run the following commands:

cd /path/to/myrepo.git

git remote add origin https://gitlab.com/username/new-repository-name.gitgit push --mirror origin

The --mirror option ensures that all branches, tags, and refs are pushed exactly as they were in the bare repository.

4. Check the Repository on GitLab:

  • Once the push is complete, go to the GitLab repository in your browser and verify that all branches, tags, and commits have been restored.
 
Did this answer your question?
😞
😐
🤩