---
publish: true
title: Backups
created: 2026-01-20T13:21:41.646-07:00
modified: 2026-01-20T13:30:33.530-07:00
cssclasses: ""
---

## Local
For me local backups happen in two main ways
1. Backups to a VPS using [[Syncthing]]
2. Backups to a USB stick that lives in my emergency kit
### USB Backups
For USB backups I had a few key requirements
1. They must be encrypted
2. Decryption should be able to take place on any Windows, Mac, or Linux device
3. Decryption must be simple enough that an intermediate user should be able to manage it given instructions (this is in case someone needs this data if I am no longer around to impart my wisdom)

Given these requirements I settled on using [[VeraCrypt]] to create an encrypted container formatted with exFat on a USB drive. This way someone can install the software and, given my key, decrypt the data.

I created the following helper functions to make this processes a little less cumbersome for myself on a monthly basis.
#### Mount/Unmount Container
```bash
vault() {
    local mount_base="/run/media/$USER"
    local mount_point="$mount_base/vault"

    _vault_find() {
        local container
        container=$(command find "$mount_base" -maxdepth 2 -name "DataVault" -type f 2>/dev/null | head -1)

        if [[ -z "$container" ]]; then
            echo "Error: DataVault not found under $mount_base" >&2
            return 1
        fi
        echo "$container"
    }

    case "${1:-}" in
        m|mount)
            local container
            container=$(_vault_find) || return 1

            if mountpoint -q "$mount_point" 2>/dev/null; then
                echo "Already mounted at $mount_point"
                return 0
            fi

            echo "Found: $container"
            sudo mkdir -p "$mount_point"
            sudo veracrypt -t --fs-options="uid=$(id -u),gid=$(id -g)" "$container" "$mount_point"
            echo "Mounted at $mount_point"
            ;;
        u|unmount)
            if ! mountpoint -q "$mount_point" 2>/dev/null; then
                echo "Not mounted"
                return 0
            fi
            sudo veracrypt -t -d "$mount_point"
            sudo rmdir "$mount_point" 2>/dev/null || true
            echo "Unmounted"
            ;;
        *)
            echo "Usage: vault {mount|m|unmount|u}"
            return 1
            ;;
    esac
}
```
#### Sync Data
```bash
vault-sync() {
    local mount_point="/run/media/$USER/vault"
    local source="$HOME/DataStore"

    if ! mountpoint -q "$mount_point" 2>/dev/null; then
        echo "Error: Vault not mounted at $mount_point" >&2
        return 1
    fi

    if [[ ! -d "$source" ]]; then
        echo "Error: Source directory $source does not exist" >&2
        return 1
    fi

    rsync -av --delete "$source/" "$mount_point/"
    echo "Sync complete"
}
```