Coder Social home page Coder Social logo

github-backup's Introduction

GitHub backup script

This directory contains a script, backup.py, for backing up GitHub repositories.

The script requires a GitHub token and a destination directory. It then uses the token to populate the destination directory with clones of all the repositories the token can access.

Repeated runs only update the already existing backups and add new repositories, if any.

Installation

Install the required Python dependencies using pip3:

$ pip3 install -r requirements.txt

Configuring

Create a token

For authorization you need to create a new personal GitHub token. You can do this from the GitHub settings, under the Personal Access Tokens tab.

Step 1

When you click the Generate new token button you enter the token creation screen. Here you should give the token a descriptive name and choose its scopes, which basically determine what the token is allowed to do.

Step 2

To backup public and private repositories you need to select only the repo scope. If you have no need for private repositories just choose the public_repo scope.

Step 3

After clicking the Generate token button you're presented with the generated token. Remember to store it now, as GitHub won't show it to you anymore!

In the next example let's assume your token is 6b86190dd45c57c1a1b039a5a54d892e019102f7 as in the above image.

Create a configuration file

To run the script you need a JSON configuration file. For an example see the included file config.json.example.

As an example let's create a file, config.json. This file should contain the token we just created and the destination directory where we want to back up the repositories:

{
    "token": "6b86190dd45c57c1a1b039a5a54d892e019102f7",
    "directory": "~/backups/github.com"
}

Choose users and organizations to back up

By default, all repositories you have read access to are backed up. To choose which users' and organizations' repos are backed up, add owners to config.json:

{
    "token": "6b86190dd45c57c1a1b039a5a54d892e019102f7",
    "directory": "~/backups/github.com",
    "owners": ["username", "anotherusername"]
}

Running

After preparing the token and the configuration file you now can run the script:

$ python3 backup.py config.json

github-backup's People

Contributors

jviide avatar osalmi avatar oherrala avatar

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.