You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 300a6d4
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+77-14Lines changed: 77 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,75 @@
1
1
# github-backup
2
2
3
-
`github-backup` discovers every repository visible to an authenticated GitHub user and backs up its complete Git object database and refs. It also backs up the authenticated user's public and secret gists.
3
+
`github-backup` discovers every repository visible to an authenticated GitHub user and backs up its complete Git object database and refs. It also backs up the authenticated user's public and secret gists. Version 1.1 can optionally add repository wikis, pull requests and other API metadata, release assets, Actions artifacts and logs, and Git LFS objects. It is designed for unattended, security-sensitive production operation.
4
4
5
5
The defaults match the safest low-overhead setup:
6
6
7
7
- local disk or a mounted NAS;
8
8
- every repository the token can access (owned, collaborator, and organization membership);
9
9
- incremental bare mirrors;
10
-
- public and secret gists included.
10
+
- public and secret gists included;
11
+
- additional GitHub service data disabled unless explicitly selected.
11
12
12
13
The user can select filesystem or S3-compatible storage, repository scope, and incremental or immutable snapshot mode at execution time or in TOML.
13
14
14
-
## What is backed up
15
+
## Backup coverage
16
+
17
+
The default run backs up:
15
18
16
19
- all Git refs and objects exposed by each repository's clone endpoint;
17
20
- owned, collaborator, and organization repositories allowed by the token;
18
21
- public and private repositories;
19
22
- public and secret gists belonging to the authenticated user;
20
23
- resource metadata and a detailed manifest for every run.
21
24
22
-
GitHub issues, pull-request discussions, releases, Actions artifacts, packages, wikis, and Git LFS payloads are separate services and are not included in version `0.1`. Normal Git commits, branches, tags, notes, and pull-request refs exposed by the clone endpoint are included. Submodule pointers are included; the referenced repository is backed up when the token can discover it independently.
25
+
Normal Git commits, branches, tags, notes, and pull-request refs exposed by the clone endpoint are included. Submodule pointers are included; the referenced repository is backed up when the token can discover it independently.
26
+
27
+
Additional components are opt-in with repeatable `--include` flags or `backup.additional_data`:
28
+
29
+
| Component | Data | Restore format and cost |
30
+
|---|---|---|
31
+
|`wikis`| Wiki Git history and refs | Separate bare mirror/bundle. Low overhead; an enabled but empty wiki is recorded as skipped. |
32
+
|`metadata`| Repository settings plus issues, issue events/comments, PRs, reviews/review comments, labels, milestones, branches, rulesets, collaborators, teams, deploy keys, webhook metadata, deployments, environments, secret names, and accessible security alerts/advisories | JSON/JSONL in a checksummed `tar.gz`. API-intensive; secret values are never available. |
33
+
|`releases`| Release metadata and every accessible binary release asset | JSONL plus binary files in `tar.gz`; may consume substantial bandwidth and storage. |
34
+
|`actions`| Metadata and downloads for non-expired Actions artifacts and completed-run logs still retained by GitHub | JSONL plus ZIP files in `tar.gz`; historical files already expired upstream cannot be recovered. |
35
+
|`lfs`| All reachable Git LFS objects |`tar.gz`; requires `git-lfs` and can be much larger than the Git repository. |
36
+
37
+
Select individual components:
38
+
39
+
```bash
40
+
github-backup run \
41
+
--include wikis \
42
+
--include metadata \
43
+
--destination /mnt/backups/github
44
+
```
45
+
46
+
Or select every supported optional component:
47
+
48
+
```bash
49
+
github-backup run --include all --destination /mnt/backups/github
50
+
```
51
+
52
+
`all` means all data classes this application can read and archive; it does not override GitHub's API restrictions. Every component archive contains `coverage.json`. Endpoints unavailable because of token permissions, feature availability, or GitHub edition are listed there and in the run manifest. Such a component has status `partial`, and the process returns exit code `2`, so monitoring cannot mistake a coverage gap for a complete backup.
53
+
54
+
### Enterprise completeness boundary
55
+
56
+
A token-based export cannot be a byte-for-byte backup of GitHub.com or GitHub Enterprise Cloud. GitHub does not return secret values, expired artifacts, deleted objects, all internal platform state, or every package-registry blob through a single backup API. Package contents should additionally be mirrored with the native npm, Maven, NuGet, RubyGems, or OCI/container registry client; secret values must be backed up at their source secret manager.
57
+
58
+
For GitHub Enterprise Server, a complete instance backup—including configuration and user data—must use the GitHub Enterprise Server Backup Service (preferred on GHES 3.17+) or the compatible legacy Backup Utilities. This project is a portable, token-authenticated complement and is useful for independent repository-level recovery, but it must not claim appliance-level completeness. See GitHub's [backup service documentation](https://docs.github.com/en/enterprise-server/admin/backing-up-and-restoring-your-instance/about-the-backup-service-for-github-enterprise-server) and [restore documentation](https://docs.github.com/en/enterprise-server/admin/backing-up-and-restoring-your-instance/restoring-from-a-backup).
23
59
24
60
## Requirements
25
61
26
62
- Python 3.11 or later;
27
63
- Git 2.30 or later;
64
+
- Git LFS when `--include lfs` is selected;
28
65
- a GitHub token;
29
66
-`boto3` only when using S3-compatible storage.
30
67
31
68
For GitHub.com, a classic personal access token normally needs `repo` for private repositories and `gist` for secret gists. Fine-grained tokens must be granted access to the intended repositories with read access to repository metadata and contents. Organization SAML/SSO policies may require the token to be authorized separately.
32
69
33
-
Never put the token in the TOML file or a command argument. The application reads it from an environment variable, injects it into Git only for the matching HTTPS host, and does not save it in remotes, logs, metadata, or manifests.
70
+
Optional data requires matching read permissions—for example Actions read for artifacts/logs, administration-related read permissions for settings, and security-event access for alert data. Classic PATs used for broad organization backups commonly require `repo`, `read:org`, `read:packages`, and `security_events`; grant only the components you actually enable. The manifest is the authoritative record of what the token could retrieve.
71
+
72
+
Never put the token in the TOML file or a command argument. The application reads it from an environment variable, injects it into Git only for the matching HTTPS host, refuses authenticated redirects, and does not save it in remotes, logs, metadata, or manifests. Plain HTTP is rejected unless an explicit testing-only override is enabled.
34
73
35
74
## Installation
36
75
@@ -84,7 +123,7 @@ github-backup run \
84
123
--cache-dir /var/cache/github-backup
85
124
```
86
125
87
-
For MinIO, Ceph, Backblaze B2, or another S3-compatible service, also pass `--s3-endpoint-url`. Standard AWS credential environment variables, profiles, instance roles, and workload identities are handled by the AWS SDK.
126
+
For MinIO, Ceph, Backblaze B2, or another S3-compatible service, also pass `--s3-endpoint-url`. Custom endpoints must use HTTPS by default; `--allow-insecure-s3-endpoint` is available only for deliberately isolated test or LAN deployments. Standard AWS credential environment variables, profiles, instance roles, and workload identities are handled by the AWS SDK.
88
127
89
128
## Configuration
90
129
@@ -106,6 +145,9 @@ The token variable name itself is configurable with `github.token_env`; its defa
106
145
| Scope |`accessible`, `owned`, `organizations`|`accessible`| Accessible is comprehensive. Owned is narrower. Organizations requires one or more `--organization` values. |
107
146
| Mode |`incremental`, `snapshot`|`incremental`| Incremental keeps the latest mirror and prunes refs deleted upstream. Snapshot creates immutable point-in-time artifacts and uses more storage. |
| Extra data | repeatable `--include`, or `--include all`| none | Adds coverage, API calls, transfer time, and storage. Components remain independent in the manifest. |
149
+
150
+
Snapshot retention defaults to unlimited (`0`). Set `backup.snapshot_retention` or `--snapshot-retention` to retain only the newest successful snapshots. For S3, retention requires list and delete permissions on the configured prefix. Bucket lifecycle policies remain recommended as a second control.
109
151
110
152
On S3, Git cannot update a remote bundle in place. A persistent local bare-mirror cache still makes GitHub downloads incremental. The application only packages and uploads a new `latest` artifact when refs changed or the remote object is absent. Snapshot mode uploads an immutable artifact on every run.
111
153
@@ -123,14 +165,22 @@ backups/
123
165
│ └── gists/GIST_ID.json
124
166
├── mirrors/
125
167
│ ├── repos/OWNER/REPOSITORY.git/
168
+
│ ├── wikis/OWNER/REPOSITORY.wiki.git/
126
169
│ └── gists/GIST_ID.git/
170
+
├── supplemental/latest/repos/OWNER/REPOSITORY/
171
+
│ ├── metadata.tar.gz
172
+
│ ├── releases.tar.gz
173
+
│ ├── actions.tar.gz
174
+
│ └── lfs.tar.gz
127
175
└── snapshots/ # snapshot mode only
128
-
└── RUN_ID/.../*.git.bundle
176
+
└── RUN_ID/... # Git bundles and component archives
129
177
```
130
178
131
-
Empty repositories have no refs and cannot be represented by a Git bundle, so snapshot mode stores them as `.empty.tar.gz` archives. Writes to JSON and local snapshot artifacts use same-filesystem atomic replacement. A process lock prevents overlapping runs against the same destination/cache. Stale local locks are recovered when their process no longer exists.
179
+
Empty repositories have no refs and cannot be represented by a Git bundle, so snapshot mode stores them as `.empty.tar.gz` archives. Writes to JSON and local snapshot artifacts use same-filesystem atomic replacement. Local/NAS runs use a process lock; S3 runs additionally use a renewable, conditional ETag lease so separate hosts cannot update the same prefix concurrently. Expired S3 leases are recovered with compare-and-swap deletion.
180
+
181
+
New local files are created under a `0077` umask, and the destination/cache must not be group- or world-accessible. Existing destinations with broader Unix mode bits are rejected. Set `allow_insecure_permissions=true` only when access is deliberately controlled by another mechanism such as a reviewed NAS ACL. The application also checks configurable minimum free space before starting.
132
182
133
-
Every completed run writes an immutable manifest and replaces `latest.json`. A partial per-resource failure returns exit code `2`, records the failure in the manifest, and leaves successful backups usable. Configuration, authentication, discovery, or storage setup failures return exit code `1`.
183
+
Every completed run writes an immutable manifest and replaces `latest.json`. A partial component or per-resource failure returns exit code `2`, records the exact result in the manifest, and leaves successful backups usable. Skipped resources such as an enabled but empty wiki are recorded without failing the run. Configuration, authentication, discovery, or storage setup failures return exit code `1`.
For S3, download the selected `.bundle` first and use the same command. Extract an `.empty.tar.gz` archive directly when restoring an empty repository. Always test restores periodically; a successful upload is not a substitute for a restore drill.
157
207
208
+
Verify every local mirror and snapshot artifact without requiring a GitHub token:
This runs Git connectivity checks on mirrors, verifies bundles against their corresponding mirrors, and validates empty-repository and supplementary archives.
215
+
216
+
Wiki mirrors and bundles use the same Git restore process. Supplementary archives are portable `tar.gz` files with JSON/JSONL metadata and original binary downloads. They deliberately preserve source records rather than attempting destructive automatic recreation through GitHub APIs; restoration should be rehearsed with an organization-specific importer and identity mapping. `verify` validates each tar container and checks its SHA-256 digest against the latest manifest.
217
+
158
218
## Scheduling
159
219
160
220
Use an external scheduler so credentials remain under the platform's secret-management policy. A systemd service can execute:
@@ -182,25 +242,28 @@ docker run --rm \
182
242
github-backup:local run --destination /backups
183
243
```
184
244
185
-
The image runs as an unprivileged user. Ensure the mounted directory is writable by UID/GID `10001` or adapt ownership to your container platform.
245
+
The image runs as an unprivileged user. Ensure the mounted directory is owned by UID/GID `10001`, is writable, and normally has mode `0700`, or adapt ownership to your container platform.
186
246
187
247
## Operational behavior
188
248
189
-
- GitHub API calls are paginated and serialized to reduce secondary-rate-limit pressure.
249
+
- GitHub API calls are paginated; discovery is serialized to reduce secondary-rate-limit pressure.
250
+
- Optional repository components use a bounded worker pool. JSON list responses are streamed to JSONL so large issue or pull-request histories do not need to reside in memory.
190
251
-`Retry-After` and primary rate-limit reset headers are honored; transient API failures use bounded retries.
191
-
- Git transfers run in a bounded worker pool. Four workers is the default; lower it on a slow NAS or constrained GitHub Enterprise Server.
252
+
- Git transfers run in a bounded worker pool and retry transient failures with backoff. Four workers and three Git retries are the defaults; lower concurrency on a slow NAS or constrained GitHub Enterprise Server.
192
253
- Initial clones are written to a temporary sibling and atomically renamed only after Git succeeds.
193
-
- Existing backups are verified as bare repositories before update.
254
+
- Existing backups are verified as bare repositories and checked with `git fsck --connectivity-only` after update.
194
255
- Deleted upstream refs are pruned in incremental mode. Use snapshots when you must retain deleted branches or tags.
195
-
- S3 uploads use the AWS SDK's adaptive retries and optional server-side encryption/storage-class settings.
256
+
- S3 uploads use adaptive retries, AES-256 server-side encryption by default, and renewable distributed leases. KMS or an explicitly disabled encryption setting can be configured when required.
196
257
- Human-readable logs are the default; `--json-logs` emits one JSON object per line.
258
+
- Application dependencies are resolved by `uv.lock`; CI uses frozen installs, audits dependencies, and pins third-party Actions to immutable commits.
197
259
198
260
## Development
199
261
200
262
```bash
201
263
python -m unittest discover -s tests -v
202
264
ruff check .
203
265
mypy src
266
+
pip-audit
204
267
```
205
268
206
269
The integration tests create real local repositories and exercise initial mirror creation, incremental updates, bundle verification, manifest writing, and credential non-persistence.
Security fixes are provided for the latest `1.x` release. Older versions should be upgraded before reporting operational problems.
6
+
7
+
## Reporting a vulnerability
8
+
9
+
Do not open a public issue for a suspected vulnerability that could expose GitHub tokens, private repository data, backup credentials, or storage contents. Use GitHub's private vulnerability reporting feature for this repository. Include the affected version, deployment model, reproduction steps, and impact. Do not include live credentials or private source code.
10
+
11
+
## Deployment requirements
12
+
13
+
- Inject GitHub and storage credentials through a secret manager or protected environment file.
14
+
- Use HTTPS GitHub and S3 endpoints. HTTP overrides exist only for deliberately isolated test systems.
15
+
- Keep filesystem destinations and S3 cache directories private to the service account. The application rejects broad Unix mode bits by default, but operators must also review ACLs and mount-level permissions.
16
+
- Enable encryption at rest for NAS volumes. S3 uploads request AES-256 server-side encryption by default; use KMS when policy requires managed keys.
17
+
- Grant the GitHub token read-only repository access and gist access. Do not grant write or administration permissions.
18
+
- Scope S3 credentials to the configured bucket prefix. Snapshot retention additionally requires list and delete permissions.
19
+
- Treat manifests and logs as sensitive metadata because they contain private repository names and failure details.
20
+
- Treat optional metadata archives as highly sensitive: they can contain private issues and pull requests, collaborator and deployment metadata, and security alerts. Secret names are exported when accessible, but GitHub never returns secret values.
21
+
- Treat release, Actions, and LFS archives as untrusted user-controlled files. Do not execute or extract them outside an isolated restore workflow.
22
+
- Monitor nonzero exit codes and test restoration on a schedule.
0 commit comments