I logged on to the discussion site today about to ask people what their favorite method of backup up Gogs was and was pleasantly surprised to see a “how to” discussing backups on Gogs. Guess great minds think alike.
I’ve been using Gogs for a while now and like any other self hosted solution losing everything because of a glitch is a fear I live with. It’s happened now to me three times having something to do with the fact that I have Gogs as a container inside of Docker. So I started writing my own backup scripts to get the job done but I hate reinventing the wheel.
So what I’ve done since Alpine is what Gogs runs under in my Docker instance is created a directory /data/backups since the /data file system is “shared” with the host. The directory is owned by userid “git” so running the backup there is going to work.
A simple script was hatched as follows:
#!/bin/bash cd /data/backups && /app/gogs/gogs backup
Can’t get more simple than that. Additionally in /etc/periodic I’ve created a subdirectory 4x-a-day into which a single file lives
#!/bin/bash su -c /opt/plb/bin/run-gogs-backup git
In /etc/crontabs/root I’ve appended the entry
0 */6 * * * run-parts /etc/periodic/4x-per-day
Stuff to do later
Given that /data is shared by the hosting server with the container I can run another cronjob that does the following:
- clean out old (say more that two weeks) backups keeping a list of those that are deleted
- take the current backups and send them to S3 for safe keeping
- remove from S3 the backups that were removed.