Skip to content

localbackup

Automatically backups current machine to local directory.

System

Features

  • Creates incremental snapshots using rsnapshot
  • Supports multiple backup targets
  • Mount/unmount hooks for external storage
  • Pre/post backup hooks for custom scripts
  • Configurable snapshot retention
  • Automatic state folder detection

Usage

Enable the localbackup service and configure backup targets:

instances = {
  localbackup = {
    module.name = "@clan/localbackup";
    module.input = "self";
    roles.default.machines."machine".settings = {
      targets.external= {
        directory = "/mnt/backup";
        mountpoint = "/mnt/backup";
      };
    };
  };
};

Commands

The service provides these commands:

  • localbackup-create: Create a new backup
  • localbackup-list: List available backups
  • localbackup-restore: Restore from backup (requires NAME and FOLDERS environment variables)

Roles

The localbackup module has the following roles:

  • default

Options for the default role

snapshots

Number of snapshots to keep

Type: signed integer

Default:

20

Declared in: clanServices/localbackup/default.nix

targets

List of directories where backups are stored

Type: attribute set of (submodule)

Declared in: clanServices/localbackup/default.nix

targets.<name>.directory

the directory to backup

Type: string

Declared in: clanServices/localbackup/default.nix

targets.<name>.mountpoint

mountpoint of the directory to backup. If set, the directory will be mounted before the backup and unmounted afterwards

Type: null or string

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.name

the name of the backup job

Type: string matching the pattern ^[a-zA-Z0-9._-]+$

Default:

"‹name›"

Declared in: clanServices/localbackup/default.nix

targets.<name>.postBackupHook

Shell commands to run after the backup

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.postMountHook

Shell commands to run after the directory is mounted

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.postUnmountHook

Shell commands to run after the directory is unmounted

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.preBackupHook

Shell commands to run before the backup

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.preMountHook

Shell commands to run before the directory is mounted

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix

targets.<name>.preUnmountHook

Shell commands to run before the directory is unmounted

Type: null or strings concatenated with "\n"

Default:

null

Declared in: clanServices/localbackup/default.nix