Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated GitHub Repository Backup #85

Open
mkubdev opened this issue Nov 3, 2023 · 2 comments
Open

Automated GitHub Repository Backup #85

mkubdev opened this issue Nov 3, 2023 · 2 comments
Assignees
Labels
linux Tag for Linux story metaphore Signs for issues that contain metaphors from punk members

Comments

@mkubdev
Copy link
Member

mkubdev commented Nov 3, 2023

The Backstory about your Linux Metaphor

I'm used to host my code on GitHub. I like GitHub a lot. I have a also a self-hosted gitlab for private work. But ensuring safety and integrity of our codebases can be scarry (imagine GitHub being offline...). One effective way to safeguard your GitHub repositories is through regular backups, and what better way to automate this process than with a scheduled cronjob on your Linux machine?

💡 3-2-1 Backup Strategy:

The 3-2-1 backup strategy, a golden rule in data backup, emphasizes redundancy and versatility. It advocates for maintaining:

  1. Three Copies of Your Data:

The original data on your local machine.
A secondary copy on another storage device.
A tertiary copy stored remotely, off-site, offering protection against catastrophic events like hardware failures or disasters.

  1. Two Different Media:

Utilize diverse storage mediums, such as local drives and cloud repositories, to mitigate risks associated with a specific type of storage failure.

  1. One Copy Off-Site:

Ensure at least one backup is stored off-site to guard against location-specific risks like theft, fire, or natural disasters.

The Linux Story!

A simple guide /w GitHub CLI and Cron Jobs.

Prerequisite

You'll need this before starting to build the backup script.

  1. Install GitHub CLI

Start by installing GitHub CLI on your machine. You can find installation instructions on the official GitHub CLI repository.

  1. Authenticate locally with GitHub CLI

Type gh auth login. You'll be redirected to your browser to validate the authentication.

Make the script!

Go somewhere on your machine, and create a file backup_repos.sh :

#!/bin/bash

# Set the path where you want to clone the repositories
BACKUP_PATH="/path/to/your/backup/location"

# Set your GitHub organization name
GH_ORG="your-organization"

# List all repositories for the authenticated user
repos=$(gh repo list $GH_ORG --json=name --limit=1000 | jq -r '.[].name')

# Go to the clone path
cd $BACKUP_PATH

# Clone each repository
for repo in $repos
do
  gh repo clone $GH_ORG/$repo
done

Important

Make sure to replace your-organization with your GitHub organization's name. Also, adjust the BACKUP_PATH to the desired directory where you want to clone all the repositories.

Save the script, and make it executable:

$> chmod +x backup_repos.sh

Setup the Cronjob:

Open the crontab file for editing it:

$> crontab -e

Add a line to schedule the backup script to run weekly. For example, to run the backup every Sunday at 8 AM:

0 8 * * 0 /path/to/backup_repos.sh

Save and exit.

Tada!

A Linux demo/repos link

No response

PayPal Link for Donation (Linux Storyteller)

No response

@mkubdev mkubdev added metaphore Signs for issues that contain metaphors from punk members linux Tag for Linux story labels Nov 3, 2023
Copy link
Contributor

github-actions bot commented Nov 3, 2023

Hello Punk! It's great having you contribute to this project

Welcome to the community :neckbeard:

If you would like to continue contributing to open source and would like to do it with an awesome inclusive community, you should join our GitHub Organisation - we help and encourage each other to contribute to open source little and often :neckbeard:. Any questions let us know.

@mkubdev
Copy link
Member Author

mkubdev commented Nov 3, 2023

I'm curious about how this will be handled:
image

Also maybe i should shorten the title? Could be bad for the cards.

@mkubdev mkubdev changed the title Automated GitHub Repository Backup: A simple guide /w GitHub CLI and Cron Jobs Automated GitHub Repository Backup Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linux Tag for Linux story metaphore Signs for issues that contain metaphors from punk members
Projects
None yet
Development

No branches or pull requests

2 participants