gitaly-backup is a command-line tool for creating and restoring backups of Git repository data from Gitaly and Gitaly Cluster.
Overview
gitaly-backup supports:
- Direct repository backups without requiring GitLab Rails
- Streaming to local filesystem or object storage (S3, Azure Blob, GCS)
- Parallel backup and restore operations
- Full and incremental backups (incremental is experimental)
- Multiple backup layouts for different use cases
Creating Backups
Step 1: Identify Repositories
For each project to backup, find the Gitaly storage name and relative path using:- The Admin area
- The repository storage API
Step 2: Create Backup Job File
Generate a JSON file with one object per line for each repository to backup:Job File Parameters
Address of the Gitaly or Gitaly Cluster server
Authentication token for the Gitaly server
Name of the storage where the repository is stored
Relative path of the repository
Name of the project (used for logging)
Step 3: Run Backup Command
Pipe the job file togitaly-backup create:
Backup Command Options
Directory or object storage URL where backup files will be created
Maximum number of parallel backups
Maximum number of parallel backups per storage
Unique identifier for the backup (determines backup path for full backups)
Filesystem layout:
legacy or pointer (experimental)Create incremental backup (experimental, requires pointer layout)
Restoring Backups
Step 1: Identify Target Repositories
For each project to restore, find the Gitaly storage name and relative path using:- The Admin area
- The repository storage API
Step 2: Create Restore Job File
Generate a JSON file with one object per line:Restore Job File Parameters
Create the repository even if no bundle exists (for compatibility with existing backups)
Step 3: Run Restore Command
Pipe the job file togitaly-backup restore:
Restore Command Options
Directory or object storage URL where backup files are stored
Maximum number of parallel restores
Maximum number of parallel restores per storage
Filesystem layout:
legacy or pointerStorage Backends
Local Filesystem
Specify a local directory path:Object Storage
gitaly-backup streams directly to object storage using gocloud.dev/blob.
Amazon S3
Azure Blob Storage
Google Cloud Storage
Backup Layouts
The-layout flag determines how backup files are organized.
Legacy Layout
The default layout, compatible with historicbackup.rake repository backups.
Directory structure:
- Creates a bundle with all references using
git bundle create repo.bundle --all - Stores bundles in a directory structure based on repository relative path
- Each backup recreates the entire directory structure
- Does not support incremental backups
Pointer Layout
Designed to support incremental backups without overwriting previous backups. Directory structure:Full Backups
- Retrieves full reference list via
ListRefsRPC, writes to001.refs - Creates bundle from reference names:
awk '{print $2}' 001.refs | git bundle create repo.bundle --stdin - Writes
LATESTpointer files to track current backup
Incremental Backups
- Calculates next increment from
LATESTfile (e.g.,001+1=002) - Retrieves current reference list, writes to
002.refs - Reads previous increment references from
001.refs - Creates bundle with negated previous targets and new references:
LATEST pointers are not found, falls back to legacy layout.