Backup

Doing backups for your data is, how to day, critical! But you need to answer a few questions first:

  • What do i want to backup?
  • Where can i store my backups?

And always remember the 3, 2, 1 rule of backup:

three copies of your data, kept in two locations and one location is off-site.

Also remember that RAID is not backup, because if you delete by error, it's gone. Also remember that SyncThing is not backup, again because if you delete by error, it's gone and what's worst, you have more than one location where you can make the error.

Backup means that your data is copied to a different location where you cannot modify or delete it directly, not by error but not even intentionally.

I have deleted files i shouldn't have, by being fully aware of what i was doing, then cursing myself profusely. I have also deleted stuff by error by typing the wrong command or running the wrong script, then cursing myself again profusely. but i have never lost data to hardware fialure, thanks to using RAID arrays.

In other words: backups are there to protect the data from yourself.

What do i want to backup?

Backing up everything would require a duplicate of your storage. Is it really needed? No it's not.

First of all, i do not backup anything that i could download again. Also, i don't backup binaries, services or the Operating System itself, anything that i can reinstall or reconfigure myself. For this, i keep notes (this wiki) and backup those notes.

I do backup all personal data like documents, scanned documents, photos taken by me, source code written by me, calendars and contacts and so on.

I also backup all my Gentoo /etc folder, because it's easy to misstep and delete something important while upgrading your system.

Where to store my backups?

Don't store them on the server. I have OpenWRT WiFi Access Points with a USB plug, so i connected a big enough SSD over USB and that's my first backup destination. I have mounted that filesystem via NFS on the server so it's easy and simple.

You will also need a second, off-site backup storage: some cloud system (like gdrive or dropbox) might work, but using your external server could even be a better idea. After all, you already pay for it and 99% of it's storage space is probably wasted anyway.

Of course, if you have your in-laws with good internet connection you might plug a usb-drive there too and use that as well… More the better…

Backup Solutions for the server

There are tons of backup solutions out there. I wanted a no fuss, jut works practical solution that is encrypted, has been around for long enough to be stable, and has outstanding user feed-backs.

I ended up going with Restic that it's simple, don't get in the way, and its rock solid.

Restic

A solid and well proven backup solution, it could be completed with a GUI to manage stuff, but it's not critical to have one.

Restic can backup anything to anywhere, including SSHFS (for remote shares) and most of commercial cloud solutions.

Installation

Unmask the latest release and emerge it:

echo "app-backup/restic ~amd64" >> /etc/portage/package.accept_keywords/restic
emerge restic

After installing Restic (the CLI) you might want to install also Backrest, a nice web GUI for Restic. Refer to this page for more details.

Usage (web GUI )

To use Backrest you can refer to it's Wiki pages.

Usage (CLI)

The following commands are always valid, specially if your Backrest is not operational.

Create new storage repository with:

 restic init --repo /backup/NAS/backup/server-etc

think of a good password.

Then perform backup to the repository:

restic -r /backup/NAS/backup/server-etc --verbose backup /etc

You will need to use the password you thought about before.

Now, save that password in a file under /root folder to be sure nobody can sniff it:

echo password > /root/restic-password

(maybe use a less conspicuous filename!)

Then you want to automate the backup, so add this line to root's crontab (crontab -e):

0 0 * * * restic -r /backup/NAS/backup/server-etc -p /root/restic-password backup /etc

There you go. You need the stored password to automate the backup.

Backup Solutions for mobile devices

Backups for your phones and tablets is a different matter because you want it fast and effective:

  • Your phone might fall into water a few minutes after taking that lifechaning picture
  • Your phone might get stolen at any time
  • Your phone might have limited bandwidth and/or data caps most of the time you are not home

Also, mounting remote shares is not practical (if even feasible in most cases) and even running cron jobs isn't.

Luckly there is a great solution that you can use, and it's SyncThing. Yes, it is not a backup solution by itself, but if you pair it to Restic once the files are stored oin the server, there you go!

Check the above linked page and install SyncThing on your server. Set it up either with a common backup user or even better setup one dedicated synthing instance for each user you want to backup. This way it's more work to set it up, but each user files are isolated, and your users can individually access them too.

Then setup syncthing on the phone and add as many sync folders as you need.