I explain my setup to keep backups of my repositories on my own server.

As a software developer GitHub has become a central part of my work.

The GitHub crew does a great job. But even for the best companies it’s possible to get in trouble some day.

Instead of setting all on a single company,
it’s a good idea to take advantage of the distributed nature of Git
and keep your own backups for emergency situations.

This can be easily automated so you don’t have to worry about it anymore.

Here is how I did it:

I decided to setup a small DigitalOcean server to backup all my repositories.

The latest version is fetched every night and I get notified in Slack.
When the notifications ever stop coming, I know something is wrong with my backups.

I use ghbackup to do this.
With ghbackup I can backup all public and private repositories I have access to in a single go,
and if a project owner would decide to remove me from a project I would still have a copy of the repositories.

Note: Inline edit code snippets below before copy&pasting them.

Follow these steps to create a similar setup or adopt it to your own needs:

We’ll be using ghbackup, sleepto and systemd.

sudo -s
curl -sL https://github.com/qvl/sleepto/releases/download/v1.6/sleepto_1.6_linux_64bit.tar.gz | tar -xzf - -C /opt sleepto
curl -sL https://github.com/qvl/ghbackup/releases/download/v1.8/ghbackup_1.8_linux_64bit.tar.gz | tar -xzf - -C /opt ghbackup
touch /opt/ghbackup-job && chmod +x $_ && echo > $_ '#!/usr/bin/env bash

github_token=""
slack_hook=""
backup_dir="/srv/github-backup"

/opt/ghbackup -secret $github_token $backup_dir \
  && curl -X POST --data-urlencode \
  "payload={\"text\": \"Successful GitHub backup.\"}" \
  $slack_hook
'
touch /etc/systemd/system/ghbackup.service && chmod 644 $_ && echo > $_ '
[Unit]
Description=Github backup
After=network.target

[Service]
ExecStart=/opt/sleepto -hour 1 /opt/ghbackup-job
Restart=always

[Install]
WantedBy=multi-user.target
'
systemctl daemon-reload
systemctl enable --now ghbackup
systemctl status ghbackup

If everything works you should get notifications about successful backups soon!

You can also trigger sleepto to run the backup job immediately:

systemctl kill -s ALRM ghbackup

After the first backup completed you find the repositories in /srv/github-backup.

This is how I setup my GitHub backups.
I hope this is helpful to others as well.

Please let me know if you run into any problems!