HUB
Sign inSign up

benedicteb/obsidian-git-backup

By benedicteb

•Updated 9 days ago

Image that syncs an Obsidian vault and automatically pushes every change to git

Image
0

4.0K

benedicteb/obsidian-git-backup repository overview

⁠obsidian-git-backup-docker

Docker Hub

A Docker image that syncs an Obsidian⁠ vault via obsidian-headless⁠ and automatically backs it up to a git repository.

Every time Obsidian Sync delivers changes, they are committed and pushed to your git remote — giving you a private, versioned backup of your vault with full history.

⁠Table of Contents

⁠Using the Pre-Built Image

Pre-built images are published to Docker Hub for linux/amd64 and linux/arm64:

docker pull benedicteb/obsidian-git-backup:latest

To use a specific version:

docker pull benedicteb/obsidian-git-backup:v0.1.0

See the Docker Hub page⁠ for available tags.

To use the pre-built image instead of building from source, update your docker-compose.yml:

services:
  obsidian-backup:
    image: benedicteb/obsidian-git-backup:latest
    # ... rest of config

To build from source instead, replace image: with build: ..

⁠How It Works

Obsidian Sync ──> obsidian-headless ──> vault directory ──> inotifywait ──> git commit + push
                  (ob sync --continuous)                    (filesystem events)
  1. obsidian-headless continuously syncs your vault from the Obsidian Sync servers to a local directory.
  2. A filesystem watcher (inotifywait) detects when files change.
  3. After a configurable debounce period (default 30s of quiet), all changes are committed and pushed to your git remote.
  4. A periodic pull (default every hour) checks the remote for changes even when no local files have changed.

The container uses s6-overlay⁠ for process supervision — both services are monitored and automatically restarted if they crash.

⁠Prerequisites

  • An Obsidian Sync⁠ subscription
  • A git repository (e.g., on GitHub, GitLab, or self-hosted)
  • Docker and Docker Compose

⁠Quick Start

⁠1. Configure
cp .env.example .env
# Edit .env and fill in the required values

You need three values:

  • OBSIDIAN_AUTH_TOKEN — Your Obsidian account auth token.

    To get it:

    1. Install obsidian-headless: npm install -g obsidian-headless
    2. Run ob login and follow the prompts
    3. Copy the contents of the auth_token file:
      • macOS: ~/.obsidian-headless/auth_token
      • Linux: ~/.config/obsidian-headless/auth_token
      • Windows: %USERPROFILE%\.obsidian-headless\auth_token

    The file contains the raw token string (not JSON). For example:

    cat ~/.config/obsidian-headless/auth_token   # Linux
    cat ~/.obsidian-headless/auth_token           # macOS
    

    Note: OBSIDIAN_AUTH_TOKEN does not use the OBSIDIAN_GIT_ prefix because it's read directly by obsidian-headless, not this project.

  • OBSIDIAN_GIT_VAULT_NAME — The name of your remote vault. Run ob sync-list-remote to see available vaults.

  • OBSIDIAN_GIT_REMOTE_URL — Your git remote SSH URL (e.g., [email protected]:username/vault-backup.git).

⁠2. Start
docker compose up -d

macOS users with bind mounts: If you're mounting host directories (e.g., ./obsidian-config:/config), you must set PUID and PGID in your .env to avoid "permission denied" errors. Run id -u and id -g to find your values (typically 501 and 20). See User / Group Identifiers⁠ for details.

⁠3. Set Up SSH Key

The container needs an SSH key to push to your git remote. You have two options:

⁠Option A: Let the container generate a key (simplest)

On first run, if no SSH key exists at /config/id_ed25519, the container generates a new ed25519 keypair. Check the logs to find the public key:

docker compose logs obsidian-backup

Look for the NEW SSH KEY GENERATED banner. Copy the public key and add it to your git server:

  • GitHub: Settings > SSH and GPG keys > New SSH key
  • GitLab: Preferences > SSH Keys > Add new key

The container retries every 30 seconds — once you add the key, it will connect automatically. No restart needed.

⁠Option B: Bring your own SSH key (bind mount)

Important: Bind mounts require matching PUID/PGID on macOS (and recommended on Linux). See User / Group Identifiers⁠.

If you already have an SSH key you want to use (e.g., a deploy key), you can bind-mount a local directory into /config that contains it.

  1. Create a config directory on the host:

    mkdir -p ./obsidian-config
    cp ~/.ssh/my_deploy_key ./obsidian-config/id_ed25519
    cp ~/.ssh/my_deploy_key.pub ./obsidian-config/id_ed25519.pub  # optional
    chmod 600 ./obsidian-config/id_ed25519
    
  2. Update your docker-compose.yml to use a bind mount instead of a named volume:

    volumes:
      - ./obsidian-config:/config
      - obsidian-vault:/vault
    
  3. Start the container:

    docker compose up -d
    

The container detects the existing key and uses it — no new key is generated.

Note: The key must be at /config/id_ed25519. The container sets permissions automatically (600 on the key), so don't worry about permission errors even if your host permissions differ.

Advanced: On first run, the container auto-generates ssh_config and known_hosts in /config/. If you need custom SSH settings (e.g., a non-standard port, proxy, or pre-seeded host keys), you can provide your own ssh_config and/or known_hosts in the same directory — the container will use them as-is and not overwrite them.

⁠4. Verify
# Watch the logs
docker compose logs -f obsidian-backup

You should see:

  1. Successful git clone
  2. Obsidian headless sync starting
  3. Filesystem watcher detecting changes
  4. Git commits and pushes

⁠Environment Variables

VariableRequiredDefaultDescription
OBSIDIAN_AUTH_TOKEN*Yes—Obsidian account auth token
OBSIDIAN_GIT_VAULT_NAMEYes—Remote vault name or ID
OBSIDIAN_GIT_REMOTE_URLYes—Git remote URL (SSH)
OBSIDIAN_GIT_USER_NAMENoobsidian-git-backupGit commit author name
OBSIDIAN_GIT_USER_EMAILNoobsidian-git-backup@localGit commit author email
OBSIDIAN_GIT_BRANCHNomainGit branch
OBSIDIAN_GIT_DEBOUNCE_SECSNo30Seconds of quiet before committing. Must be a positive integer. For large vaults, consider 60+.
OBSIDIAN_GIT_PULL_INTERVALNo3600How often (seconds) to pull remote changes when no local files have changed. Set to 0 to pull only before each push. Minimum 10 when enabled.
OBSIDIAN_GIT_E2EE_PASSWORDNo—E2E encryption password
OBSIDIAN_GIT_SYNC_FILE_TYPESNoimage,audio,video,pdf,unsupportedWhich attachment types Obsidian Sync downloads to disk. Separate from LFS. See Sync Filtering⁠.
OBSIDIAN_GIT_SYNC_CONFIGSNo(all categories).obsidian config categories to sync, including community plugins. See Sync Filtering⁠.
OBSIDIAN_GIT_LFS_ENABLEDNofalseStore binary attachments via Git LFS instead of directly in git. Separate from sync filtering. See Git LFS⁠.
OBSIDIAN_GIT_LFS_EXTENSIONSNo(see below)File extensions git stores via LFS. Separate from sync filtering.
PUIDNo1000Your host user ID. Needed for bind mounts — run id -u to find it.
PGIDNo1000Your host group ID. Needed for bind mounts — run id -g to find it.

* OBSIDIAN_AUTH_TOKEN is read directly by obsidian-headless. It does not use the OBSIDIAN_GIT_ prefix because it's not a variable defined by this project.

⁠Volumes

PathRequiredDescription
/configYesPersistent configuration and SSH keys. Must survive restarts. Named volume (default) or bind mount (see Option B⁠).
/vaultNoVault data and git working tree. Can be re-synced/re-cloned if lost.

⁠User / Group Identifiers (PUID/PGID)

When using bind mounts (mapping a host directory into the container), you must tell the container to run as your host user to avoid permission conflicts. This follows the linuxserver.io⁠ convention.

Find your UID and GID:

id -u   # → e.g. 501 on macOS, 1000 on Linux
id -g   # → e.g. 20 on macOS, 1000 on Linux

Then set them in your environment or docker-compose.yml:

environment:
  - PUID=501
  - PGID=20

Or with docker run:

docker run -e PUID=501 -e PGID=20 ...

Note: PUID/PGID are not needed when using Docker named volumes (the default in docker-compose.yml). Named volumes are managed by Docker and don't have host permission issues. PUID/PGID are only needed when you bind-mount host directories (e.g., ./local/config:/config).

⁠Architecture

The container runs four s6-rc services:

base
  └── init-usermap (oneshot) — remaps UID/GID to match PUID/PGID
        └── init-config (oneshot) — validates env, sets up SSH, clones git, configures ob
              ├── obsidian-sync (longrun) — ob sync --continuous
              └── git-watcher (longrun) — inotifywait + git commit/push
  • init-usermap: Remaps the container's obsidian user/group to match PUID/PGID. Fixes ownership of /config and /vault. Runs once.
  • init-config: Validates environment, sets up SSH, clones git repo, configures obsidian-headless. Runs once at startup.
  • obsidian-sync: Runs ob sync --continuous as the obsidian user. Auto-restarted by s6 if it crashes.
  • git-watcher: Monitors /vault with inotifywait as the obsidian user. Debounces, then commits and pushes. Auto-restarted by s6 if it crashes. On graceful shutdown, any pending changes in the debounce window are committed.

⁠Multiple Vaults

Run one container per vault. Each needs its own .env file (with a different OBSIDIAN_GIT_VAULT_NAME and OBSIDIAN_GIT_REMOTE_URL) and separate volumes:

services:
  vault-personal:
    image: benedicteb/obsidian-git-backup:latest
    env_file: .env.personal
    volumes:
      - config-personal:/config
      - vault-personal:/vault

  vault-work:
    image: benedicteb/obsidian-git-backup:latest
    env_file: .env.work
    volumes:
      - config-work:/config
      - vault-work:/vault

⁠Sync Filtering

By default, the container syncs everything — all attachment types (images, audio, video, PDFs, and unrecognized formats) and all .obsidian configuration (including community plugins). You can narrow this down using two environment variables.

Note: These settings control what Obsidian Sync downloads to disk. They are separate from Git LFS⁠, which controls how git stores files that are already on disk.

⁠File types

OBSIDIAN_GIT_SYNC_FILE_TYPES controls which attachment types are synced:

ValueWhat it includes
imagePNG, JPG, JPEG, GIF, BMP, WebP, SVG, AVIF
audioMP3, WAV, M4A, 3GP, FLAC, OGG, OGA, Opus
videoMP4, WebM, OGV, MOV, MKV
pdfPDF files
unsupportedAny file extension not recognized by Obsidian (.blend, .psd, .csv, .yaml, etc.)

The default (image,audio,video,pdf,unsupported) syncs all file types. Markdown (.md), Canvas (.canvas), and Base (.base) files are always synced regardless of this setting.

To sync only standard types (excluding unrecognized formats):

OBSIDIAN_GIT_SYNC_FILE_TYPES=image,audio,video,pdf
⁠Config categories

OBSIDIAN_GIT_SYNC_CONFIGS controls which .obsidian settings are synced:

ValueWhat it includes
appapp.json, types.json
appearanceappearance.json
appearance-dataThemes and CSS snippets
hotkeyhotkeys.json
core-plugincore-plugins.json and migration settings
core-plugin-dataCore plugin settings (JSON files in .obsidian/)
community-plugincommunity-plugins.json (plugin install list)
community-plugin-dataPlugin data (.obsidian/plugins/*/manifest.json, main.js, styles.css, data.json)

The default syncs all categories, including community plugins. To exclude community plugins (reduces commit noise from frequently-updated plugin data):

OBSIDIAN_GIT_SYNC_CONFIGS=app,appearance,appearance-data,hotkey,core-plugin,core-plugin-data

⁠Git LFS (Large File Storage)

Git LFS is disabled by default. When enabled, binary files — images, PDFs, videos, audio, and other attachments — are stored via Git LFS⁠ instead of directly in the git repository. This keeps your repo small and fast to clone, even if your vault contains large attachments.

To enable LFS, add to your .env:

OBSIDIAN_GIT_LFS_ENABLED=true

Upgrading from an earlier version? If you used a version of this image where LFS was enabled by default, you must add OBSIDIAN_GIT_LFS_ENABLED=true to your .env to keep LFS active. Without it, a fresh container start may leave LFS pointer stubs in /vault instead of real file content — the container detects this and refuses to start, with instructions to fix it.

Requirements: Your git remote must support LFS. GitHub, GitLab, Gitea, Forgejo, and Bitbucket all support LFS. Many self-hosted git servers do not have LFS enabled — check that your server has LFS storage configured, or test with git lfs ls-files after your first push.

GitHub Free accounts include 1 GB LFS storage and 1 GB/month bandwidth. Vaults with many large images or PDFs may exceed this. Check your GitHub billing settings⁠ if pushes fail with quota errors.

⁠Default tracked extensions

The default extension list covers common binary formats found in Obsidian vaults:

CategoryExtensions
Imagespng, jpg, jpeg, gif, bmp, webp, tif, tiff
Videomp4, mov, avi, mkv, webm
Audiomp3, wav, ogg, flac, m4a, aac
Documentspdf, doc, docx, xls, xlsx, ppt, pptx
Archiveszip, tar, gz, 7z, rar
Fontswoff, woff2, ttf, otf

Note: SVG files are not tracked by LFS by default because they are XML text — they diff meaningfully and compress well in git. Similarly, .excalidraw and .canvas files are JSON text and should stay in git. If you need to add SVG to LFS (e.g., for very large auto-exported SVGs), include svg in your OBSIDIAN_GIT_LFS_EXTENSIONS override.

⁠Customizing tracked extensions

Override the default list by setting OBSIDIAN_GIT_LFS_EXTENSIONS to a comma-separated list of file extensions (without dots):

Warning: This replaces the entire default list — it is not additive. To add one extension, copy the full default list and append yours.

# Add .heic to the defaults (must copy full list + append)
OBSIDIAN_GIT_LFS_EXTENSIONS=png,jpg,jpeg,gif,bmp,webp,tif,tiff,mp4,mov,avi,mkv,webm,mp3,wav,ogg,flac,m4a,aac,pdf,doc,docx,xls,xlsx,ppt,pptx,zip,tar,gz,7z,rar,woff,woff2,ttf,otf,heic

To track only specific formats:

# Only track images and PDFs
OBSIDIAN_GIT_LFS_EXTENSIONS=png,jpg,jpeg,gif,pdf
⁠What happens to existing binary files?

Enabling LFS only affects new or modified files from that point forward. Binary files already committed directly to git remain in git history as regular objects. Only new attachments will be stored via LFS.

To migrate existing files, you would need to run git lfs migrate manually — see the Git LFS documentation⁠. This is optional.

⁠Unraid Installation

This image includes an Unraid Docker template. The template is currently in beta — please report issues⁠ if you encounter problems.

Note: This template is not yet in the official Community Applications⁠ search index. The install method below does not require the CA plugin — it uses Unraid's built-in Docker Manager template system, which works on all Unraid versions (6.x and 7.x).

⁠Before You Start

Before installing on Unraid, you need to obtain your Obsidian auth token on a desktop or laptop (not on the Unraid server — a web browser is required):

  1. Install Node.js⁠ (LTS version recommended)
  2. Run npm install -g obsidian-headless
  3. Run ob login — this opens a browser for authentication
  4. Copy the token from the auth_token file:
    • macOS: ~/.obsidian-headless/auth_token
    • Linux: ~/.config/obsidian-headless/auth_token
    • Windows: %USERPROFILE%\.obsidian-headless\auth_token

You also need a git repository with SSH access (e.g., a private GitHub repo).

⁠Add the Template

Open a terminal in the Unraid WebGUI (terminal icon in the top-right) or connect via SSH, then run:

curl -fsSL -o /boot/config/plugins/dockerMan/templates/obsidian-git-backup.xml \
  https://raw.githubusercontent.com/benedicteb/obsidian-git-backup-docker/main/obsidian-git-backup.xml

No output means success. If you see an error, check your internet connection.

Then:

  1. Go to the Docker tab.
  2. Click Add Container at the bottom of the page.
  3. In the Template dropdown at the top of the form, select obsidian_git_backup. The form will populate with all the configuration fields.

To update the template later (e.g., after a new release adds fields), re-run the curl command above.

⁠Configure the Container

Tip: For best I/O performance with frequent small file changes, ensure your appdata share uses "cache-prefer" or "cache-only" mode (Shares tab) before installing. The default appdata paths will then land on the cache drive automatically.

The template form includes all required and optional settings:

FieldRequiredNotes
Obsidian Auth TokenYesThe token from ob login above. Masked in the UI.
Vault NameYesExactly as shown in the Obsidian app (case-sensitive). Run ob sync-list-remote to list vaults. You can also use the vault UUID.
Git Remote URLYesSSH URL, e.g. [email protected]:user/vault-backup.git
E2EE PasswordIf encryptedOnly for E2E encrypted vaults. Your git backup will contain plaintext notes — secure your git remote accordingly.
Config StorageYesDefault: /mnt/user/appdata/obsidian-git-backup/config
Vault StorageRecommendedDefault: /mnt/user/appdata/obsidian-git-backup/vault

Additional settings (git author, branch, debounce period) are under Advanced View.

Note: PUID/PGID default to 99/100 (Unraid's nobody/users), which is correct for most Unraid setups. Changing these means Unraid's New Permissions tool may create files with unexpected ownership.

The container is managed by Unraid's Autostart mechanism — no --restart policy is set, which lets Unraid control the container lifecycle cleanly across array start/stop cycles.

⁠After Installing
  1. Go to the Docker tab, click the container's name or icon to open the context menu, and select Logs.
  2. Look for the NEW SSH KEY GENERATED banner.
  3. Copy the public key and add it to your git server:
    • GitHub: Settings → SSH and GPG keys → New SSH key
    • GitLab: Preferences → SSH Keys → Add new key
  4. The container retries every 30 seconds — once you add the key, it connects automatically. No restart needed.
⁠Multiple Vaults on Unraid

Run one container per vault. To add another vault, install the template again with:

  • A different container name (e.g., obsidian-git-backup-work)
  • Different vault path (e.g., /mnt/user/appdata/obsidian-git-backup/vault-work)
  • A different vault name and git remote URL

Containers can share the same config path — it only contains the SSH key and SSH settings, which are safe to share. Only the vault path must be unique per container.

Each container counts as one device on your Obsidian Sync plan — check your plan's device limit at obsidian.md/account⁠.

Warning: Never point two containers at the same vault simultaneously. Each container must have its own vault path — sharing vault paths between containers causes silent data corruption.

⁠Troubleshooting on Unraid

Container keeps restarting / inotifywait crashes on a busy server:

The filesystem watcher uses inotify, which has a host-level watch limit shared by all containers. On busy Unraid servers, the default limit (8,192) can be exhausted. Check the current value:

cat /proc/sys/fs/inotify/max_user_watches

To raise it (64× the default):

# Temporary (until next reboot):
echo 524288 > /proc/sys/fs/inotify/max_user_watches

# Persistent — add to /boot/config/go (safe to run multiple times):
grep -q 'max_user_watches' /boot/config/go || \
  echo 'echo 524288 > /proc/sys/fs/inotify/max_user_watches' >> /boot/config/go

⁠Publishing

Pushes to main automatically build and publish the Docker image to Docker Hub⁠.

Version tags are created automatically based on conventional commits⁠:

Commit prefixVersion bumpExample
feat!: or BREAKING CHANGE in bodyMajor (0.1.0 → 1.0.0)feat!: rename all env vars
feat:Minor (0.1.0 → 0.2.0)feat: add LLM commit messages
fix:, docs:, chore:, etc.Patch (0.1.0 → 0.1.1)fix: handle empty vault

Two GitHub Actions secrets must be configured (Settings → Secrets and variables → Actions):

SecretWhere to get it
DOCKERHUB_USERNAMEYour Docker Hub username
DOCKERHUB_TOKENDocker Hub → Account Settings → Security → New Access Token

⁠Limitations (PoC)

  • SSH only — HTTPS git remotes are not supported yet.
  • No LLM commit messages — Commits use simple timestamps. AI-generated messages are planned for a future release.
  • Large syncs may produce partial commits — The debounce timer helps but if an Obsidian sync takes longer than the debounce period, intermediate state may be committed. Increase OBSIDIAN_GIT_DEBOUNCE_SECS for large vaults.
Tag summary
Recent tags
Content type
Image
Digest
sha256:ed6697609…
Size
81.9 MB
Last updated
9 days ago
docker pull benedicteb/obsidian-git-backup:latest