Backups
Introduction to Backups
When you're managing your own services, creating regular backups is crucial to ensure your data's safety. This guide introduces you to Clan's built-in backup functionalities. Clan supports backing up your data to both local storage devices (like USB drives) and remote servers, using well-known tools like borgbackup and rsnapshot. We might add more options in the future, but for now, let's dive into how you can secure your data.
Backing Up Locally with Localbackup
What is Localbackup?
Localbackup lets you backup your data onto physical storage devices connected to your computer, such as USB hard drives or network-attached storage. It uses a tool called rsnapshot for this purpose.
Setting Up Localbackup
- Identify Your Backup Device:
First, figure out which device you'll use for backups. You can see all connected devices by running this command in your terminal:
Look for the device you intend to use for backups and note its details.
- Configure Your Backup Device:
Once you've identified your device, you'll need to add it to your configuration.
Here's an example NixOS configuration for a device located at /dev/sda2
with an ext4
filesystem:
{
fileSystems."/mnt/hdd" = {
device = "/dev/sda2";
fsType = "ext4";
options = [ "defaults" "noauto" ];
};
}
Replace /dev/sda2
with your device and /mnt/hdd
with your preferred mount point.
- Set Backup Targets: Next, define where on your device you'd like the backups to be stored:
Change /mnt/hdd
to the actual mount point you're using.
- Create Backups: To create a backup, run:
This command saves snapshots of your data onto the backup device.
- Listing Backups: To see available backups, run:
Remote Backups with Borgbackup
Overview of Borgbackup
Borgbackup splits the backup process into two parts: a backup client that sends data to a backup server. The server stores the backups.
Setting Up the Borgbackup Client
- Specify Backup Server:
Start by indicating where your backup data should be sent. Replace hostname
with your server's address:
{
clan.borgbackup.destinations = {
myhostname = {
repo = "borg@backuphost:/var/lib/borgbackup/myhostname";
};
};
}
- Select Folders to Backup:
Decide which folders you want to back up. For example, to backup your home and root directories:
- Generate Backup Credentials:
Run clan facts generate <yourmachine>
to prepare your machine for backup, creating necessary SSH keys and credentials.
Setting Up the Borgbackup Server
- Configure Backup Repository:
On the server where backups will be stored, enable the SSH daemon and set up a repository for each client:
{
services.borgbackup.repos.myhostname = {
path = "/var/lib/borgbackup/myhostname";
authorizedKeys = [
(builtins.readFile (config.clan.core.clanDir + "/machines/myhostname/facts/borgbackup.ssh.pub"))
];
};
}
Ensure the path to the public key is correct.
- Update Your Systems: Apply your changes by running
clan machines update
to both the server and your client
Managing Backups
- Scheduled Backups:
Backups are automatically performed nightly. To check the next scheduled backup, use:
- Listing Backups: To see available backups, run:
- Manual Backups: You can also initiate a backup manually: