Coder Social home page Coder Social logo

github-backup's Introduction

Github Backup

Based on the work of Richard Bairwell.

This script offers two methods to save your Github repositories:

  • An advanced method with Node.js (Linux/MacOS/Windows).
  • A simple sh script designed to run on the Synology DS range of file storage servers to backup all repositories (and wikis) for a user from Github (Linux/MacOS/WSL).

Bonus in sh version:

  • You can auto-push your backup to a Gitea server

With Docker

# node.js version
docker run --rm -v '/mnt/x/backups':/mnt/backups --env GITHUB_BACKUP_PATH=/mnt/backups --env GITHUB_BACKUP_USER=[company] --env GITHUB_BACKUP_TOKEN=[YOUR TOKEN] ghcr.io/creadigme/github-backup:0.1.0
# bin/sh version
docker run --rm -v '/mnt/x/backups':/mnt/backups --env GITHUB_BACKUP_PATH=/mnt/backups --env GITHUB_BACKUP_USER=[company] --env GITHUB_BACKUP_TOKEN=[YOUR TOKEN] ghcr.io/creadigme/github-backup-sh:0.1.0

Prerequist

  • Ensure you have git installed on the Server/Synology.

Note: on DSM Synology - this can be download from the SynoCommunity.

  • Now login to Github and go to Fine-grained personal access tokens and create a fine-grained token with the following repositories permissions:

    • Read access to code and metadata
  • Add this token as environment variable GITHUB_BACKUP_TOKEN (GITHUB_BACKUP_TOKEN="[PUT YOUR TOKEN HERE BETWEEN THE QUOTES]").

  • Add the target github name as environment variable GITHUB_BACKUP_USER (GITHUB_BACKUP_USER="[PUT THE TARGET USERNAME]").

  • Ensure the environment variable GITHUB_BACKUP_PATH backup path is correct and set (GITHUB_BACKUP_PATH="/volume1/serverBackups/github/backup").

Node.js way

Prerequist

  • Ensure you have node.js 18 (or later) installed.

Note: on DSM Synology - this can be download from the SynoCommunity.

Installation

  • Copy ./build/github-backup.js over to your Synology/Server/[...].

Note: on DSM Synology - all via SSH.

Usage

# Without token (public repositories)
GITHUB_BACKUP_PATH=./backups GITHUB_BACKUP_USER=microsoft node ./github-backup.js

# With token (public+private repositories)
GITHUB_BACKUP_PATH=./backups GITHUB_BACKUP_TOKEN=XXXX node ./github-backup.js

/bin/sh way

Prerequist

  • cUrl
  • jq but these seem standard on Synologys.

Installation

  • Copy the script (./scripts/github-backup.sh) over to your Synology/Server/[...].

Note: on DSM Synology - all via SSH.

Usage

# Without token (public repositories)
GITHUB_BACKUP_PATH=./backups GITHUB_BACKUP_USER=microsoft ./github-backup.sh

# With token (public+private repositories)
GITHUB_BACKUP_PATH=./backups GITHUB_BACKUP_TOKEN=XXXX ./github-backup.sh

Bonus - Gitea

Prerequist

  • Generate a token with this command:
curl -H "Content-Type: application/json" -d '{\"name\":\"<Token Name>\"}' -u <user>:<password> http://<gitea-host>/api/v1/users/<user>/tokens
# {"id":1,"name":"Token Name","sha1":"XXXXX","token_last_eight":"YYYYY"}
# The token: the sha1 value.

Auto push to Gitea

GITHUB_BACKUP_PATH=./backups GITHUB_BACKUP_USER=creadigme GITHUB_BACKUP_TOKEN=[GITHUB_TOKEN] GITEA_URL=[GITEA_URL] GITEA_USER=[GITEA_USER] GITEA_API_TOKEN=[GITEA_TOKEN] EXTRA_REPO_STEP=./scripts/mirror-2-gitea.sh ./scripts/github-backup.sh

github-backup's People

Contributors

aegenet avatar miniben-90 avatar pmilano1 avatar rbairwell avatar

Forkers

aegenet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.