The goal of this article is to explain how to back up all your Gitlab repositories with a utility script.
I wrote this script in order to be able to:
- the personal user repositories private and public,
- the user organization repositories,
- the fork repositories.
When the script is run for the first time, it will retrieve all the repositories if the repositories have been previously retrieved it will do an update.
The repository name with space will be replace in clone folder by -. Example the repository name like repo 1 will be clone with name repo-1.
Before getting started, you'll need to install Python and Git on your machine:
After installation, you can clone the utility script at the following address: Gitlab Clone Repo
Go to your Gitlab account to generate a token with read-only authorization as below:
If you want to update fork repositories, you need to give workflow authorization to allow repositories to be updated. Activate the option as shown below:
In the clone utility project repository folder, create the file .env with the following contents:
# Clone repo host
DOMAIN = gitlab.com
# Domain protocol type http or https
PROTOCOL = https
# Access Token To Domain
TOKEN = your_generate_token_here
# Username gitlab
USERNAME = your_gitlab_username
# Storage Folder => Folder where the repositories will be save => example /home/toto or C:\users\toto for windows
FOLDER = folder_path_here
You must enter specific values as shown in the example below:
During execution, destination folders will be created if they do not exist.
Run the following command in the project folder (must be run once):
python -m venv env
python3 -m venv env
or for ubuntu
If you encounter an error, please check the following link: https://gist.github.com/frfahim/73c0fad6350332cef7a653bcd762f08d
Run the following command to activate the environment:Lancez la commande suivante pour activer l'environnement:
or on windows
Install the modules from the command:
pip install -r requirements.txt
Run the backup script with the command:
At the end you'll have all the repositories in the destination folder.
Note that for each execution you have the log generated inside utility script folder inside subfolder logs.
For Github version you can visit Github Backup.