Skip to main content

gitlab-project-export

Simple python project for exporting gitlab projects with Export Project feature in GitLab API.

Primary used for remote backup of projects in GitLab.com to private storage server.

Breaking Changes

05-2020

Code was modified to work with Python3, not longer compatible with Python2.

Prerequisite

Install

Simply install via pip:

pip install gitlab-project-export

or

pip install git+https://github.com/rvojcik/gitlab-project-export

or clone the project and install manually:

git clone https://github.com/rvojcik/gitlab-project-export
cd gitlab-project-export/
sudo python3 setup.py install

or use it without installing to your environment (install only requirements):

git clone https://github.com/rvojcik/gitlab-project-export
cd gitlab-project-export/
pip install -f requirements.txt

Prepare and edit your config file

mv config.yaml-example config.yaml

Simply run the script with optional config parameter

./gitlab-project-export.py -c /path/to/config.yaml

Configuration

System uses simple yaml file as configuration.

Example below

gitlab:                                                   - gitlab configuration
  access:
    gitlab_url: "https://gitlab.com"                      - Gitlab url, official or your instance
    token: "MY_PERSONAL_SECRET_TOKEN"                     - personal access token
  projects:                                               - list of projects to export
    - rvojcik/example-project

backup:                                                   - backup configuration
  project_dirs: True                                      - store projects in separate directories
  destination: "/data/backup"                             - base backup dir
  backup_name: "gitlab-com-{PROJECT_NAME}-{TIME}.tar.gz"  - backup file template
  backup_time_format: "%Y%m%d"                            - TIME tamplate, use whatever compatible with
                                                            python datetime - date.strftime()

Backup Usecase in cron

Create cron file in /etc/cron.d/gitlab-backup

With following content

MAILTO=your_email@here.tld

0 1 * * * root /path/to/cloned-repo/gitlab-project-export.py -c /etc/gitlab-export/config.yaml

Migration Usecase

First create two config files

config1.yaml for exporting our project from gitlab.com

gitlab:                                                   - gitlab configuration
  access:
    gitlab_url: "https://gitlab.com"                      - Gitlab url, official or your instance
    token: "MY_PERSONAL_SECRET_TOKEN"                     - personal access token
  projects:                                               - list of projects to export
    - rvojcik/project1
    - rvojcik/project2

backup:                                                   - backup configuration
  project_dirs: False                                     - store projects in separate directories
  destination: "/data/export-dir"                             - base backup dir
  backup_name: "gitlab-com-{PROJECT_NAME}-{TIME}.tar.gz"  - backup file template
  backup_time_format: "%Y%m%d"                            - TIME tamplate, use whatever compatible with
                                                            python datetime - date.strftime()

and config2.yaml where we need only gitlab access part for importing projects to private gitlab instance

gitlab:                                                   - gitlab configuration
  access:
    gitlab_url: "https://gitlab.privatedomain.tld"        - Gitlab url, official or your instance
    token: "MY_PERSONAL_SECRET_TOKEN"                     - personal access token

Now it's time to export our projects

./gitlab-project-export.py -c ./config1.yaml -d

Your projects are now exported in /data/export-dir

After that we use gitlab-project-import.py with config2.yaml for importing into our pricate gitlab instance.

./gitlab-project-import.py -c ./config2.yaml -f ./gitlab-com-rvojcik-project1-20181224.tar.gz -p "rvojcik/project1"
./gitlab-project-import.py -c ./config2.yaml -f ./gitlab-com-rvojcik-project2-20181224.tar.gz -p "rvojcik/project2"

Done ;)

Release files for gitlab-project-export 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gitlab-project-export 0.1.2
File Size Uploaded
gitlab-project-export-0.1.2.tar.gz 19.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gitlab-project-export 0.1.2
File Interpreter ABI Platform
gitlab_project_export-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / gitlab-project-export-0.1.2.tar.gz

Download URL gitlab-project-export-0.1.2.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e7401b2a309c4baca9525d9c836da122670f43c508276922eb1644fe4aa01d6d
BLAKE2b-256 checksum
How to use checksums
65da3dea875ba98a18f5fd5c7e291b95f1da9928574c6623352e0d2d33e51a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

Release files / gitlab_project_export-0.1.2-py3-none-any.whl

Download URL gitlab_project_export-0.1.2-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88ba449e8adeaa427ac3c8e1fddf88d5a58c6d1480b3423801f891b38e326543
BLAKE2b-256 checksum
How to use checksums
c7d05483c27f65a5957e4dcf34e1d00e6ebfbeb790471f9b1ca1c5bc287b7947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page