Data loss is not a problem specific to self-hosting.
Whenever you administrate a system that contains valuable data (a self-hosted network service/application, you personal computer, phone...), think about a backup and recovery strategy for common (and less common) data loss cases:
- you delete a valuable file by accident
- a bad actor deletes or encrypts the data (ransomware)
- the device gets stolen, or destroyed (hardware failure, power surge, fire, flood, hosting provider closing your account)
- anything you can think of
For these different scenarios try to find a working backup/restore strategy. For me they go like
- Automatic, daily local backups (anything on my server gets backed up once a day to a
backups
directory usingrsnapshot
). Note that file sync like nextcloud won't protect you against this risk, if you delete a file on the nextcloud client it's also gone on the Nextcloud server (though there is a recycle bin). Local backups are quick and easy to restore after a simple mistake like this. They wont protect you against 2 and 3. - Assuming an attacker gains access to your machine they will also destroy or encrypt your local backups. My strategy against this is to pull a copy of the latest local backup, weekly, to a USB drive, through another computer, using
rsync/rsnapshot
. Then I unplug the USB drive, store it somewhere safe outside my home, and plug in a second USB drive. I rotate the drives every week (or every 2 weeks when I'm lazy - I have set up a notification to nag me to rotate the drive every saturday, but I sometimes ignore it) - The USB strategy also protects me against 3. If both my server and main computer burn down, the second drive is still out there, safely encrypted. It's the worst case scenario, I'd probably spend quite some time setting up everything again (though most of the setup is automated), and at this point I'd have bigger problems like, you know, burned down house. But I'd still have my data.
There are other strategies, tools, etc, this one works for me. It's cheap (the USB drives are a one-time investment), the only manual step is to rotate the drives every week or so.