Skip to content

A simple Ruby script to back up GitHub repositories and gists locally

License

Notifications You must be signed in to change notification settings

rubenarakelyan/backup-github

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backup GitHub

A simple Ruby command line script that downloads zip files of all your GitHub repositories and Gists for backup purposes.

Setup

Ensure you have the correct Ruby version and the bundler gem installed. All other gems will be installed automatically the first time you run the script.

Configuration

Run ruby backup.rb config --github-access-token GITHUB_ACCESS_TOKEN --backup-directory BACKUP_DIRECTORY, or copy config.example.yaml to config.yaml and edit the values.

The script uses a fine-grained personal access token, which you can create at https://github.com/settings/personal-access-tokens/new. Select "all repositories", then give read-only access for "contents" (under repository permissions) and read-write access for "gists" (under "account permissions"). The script does not write anything, but there is no read-only permission level for gists.

The backup directory can be anywhere on your file system that you have write access to, as either an absolute or relative (from the script directory) path. A ./backups directory is provided as a default.

Running backups

There are separate commands for backing up repositories and gists.

Backing up repositories

Run ruby backup.rb backup-repos. By default, this will only get public repositories. Add --private-repos to also get private repositories. For each repository, the script will download a zip file containing the current state of the default branch.

Backing up gists

Run ruby backup.rb backup-gists. This will get all gists (public and secret). For each gist, the script will download a zip file containing the latest version of all the files in that gist.

Errors

Most errors are captured and presented with as much information as possible.

If you start seeing 403 errors, it's very likely that you've hit a rate limit. Try again later, and consider increasing the sleep duration between each request.

About

A simple Ruby script to back up GitHub repositories and gists locally

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages