I’ve been thinking about writing up the change I’ve made to my backup system for a little while now, it takes me time to consolidate my thoughts as I tend to ramble in random directions for awhile. This seems like as good a time and place as any!
In a previous post, I mentioned that I was mostly backing up through a bash script that I custom wrote to Nextcloud, and then relying on the versioning system in Nextcloud as my “deltas” (foreshadowing). The script I used would use tar to build an archive, gz to compress the archive, and then gpg to encrypt the compressed archive. Then I would use curl to upload the backup to Nextcloud.
This idea was cool (to me), as it taught me about building a repeatable backup process, deploying that process with ansible, and managing files with Nextcloud. However, this idea was also fraught with problems:
- Often times the script would fail and had no self-healing. I had to rely on Icinga2 alerts days after to tell me that a backup failed and then I would manually go in and resolve the issue.
- Relying on Nextcloud’s versioning system does work, but it also very much does eat file space. Neither my script, nor the versioning system, does any de-duplication so 600GB of backups from my script required over 2TB of total disk space on my Nextcloud server.
So I finally decided it’s time to fix these issues and get a more reliable setup. The criteria I used for this was:
- De-duplication is a top priority. I don’t want backups taking up 2TB of space (unless it really is that much data)
- More reliability requiring less manual intervention from me
- Repeatable and deployable, something that works for a server, laptop, desktop, or the offsite backup process
What do I use? Borg Backup. It meets each of my criteria with de-duplication, encryption, compression, and a repeatable and deployable process. Backups have been running for almost a month now, and I’ve only used 122GB of space!
Where do backups go? I chose to re-partition my RAID array with a /data/nextcloud folder and a /data/backups folder, where Borg stores backups.
How often do they run? All backups run nightly. Offsite backup runs once a week to an external USB drive, which every other weekend I physically hand off the drive to a family member who backups up the data to their NAS.
Have I tested a restore? Yes! Borg’s ability to mount your backup as a file system and browse the archives and even copy a file off to the main drive is an insanely useful feature. It absolutely saved my butt when a Raspberry Pi went down (bad SD card) and I needed to get several config files to push to another machine. I mounted the backup on my desktop, copied the files off the mounted archive, and rsync’d them to the new machine, easiest restore I’ve ever done.
I wrote some BASH scripts as wrappers around the Borg commands, put it in a repo, and then used Ansible to deploy this across my network. The borg-init script initializes the program. The borg-backup script does the backup. If you want to check them out, see my repo here, which also includes the files to use for what to backup, what to exclude, pre-scripts, post-scrips, and ansible playbooks. I have two more scripts left to write and some documentation to add before moving it to the main branch, hence why the link is to develop.
So far, Borg has been incredible for what I needed and backups run smoothly every night. I haven’t had to manually intervene in a few weeks now.