BorgBackup to a Synology NAS over SSH
Borg command cheat sheet to back up, list, prune and search archives on a Synology NAS.
BorgBackup can back up a Linux machine to a Synology NAS over SSH. Borg must also be installed on the NAS (via the Synology package manager), which is why every command passes --remote-path. The examples below use borg 1.2.7, a placeholder host example.com and SSH port 222.
Preparation
Set the repository passphrase in the environment (use your own value and never commit it):
export BORG_PASSPHRASE='<PASSWORD>'
Initialise the repository:
borg init --encryption=repokey --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg/
Create a backup
# One folder
borg create --stats --progress --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::second /home/user/
# Whole system
borg create --stats --progress --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::second /
# Several folders, archive named with the date
borg create --stats --progress --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::myhost-{now:%Y-%m-%d} /home/ /etc/ /usr/ /var/log/
# Archive named with date, time and user
borg create --stats --progress --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::data-$(date +"%Y-%m-%d-%H%M%S"-${USER}) /path/to/data/
List, inspect and compare
# List archives
borg list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg
# List the content of one archive
borg list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::second
# Repository information
borg info --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg
# Differences between two archives
borg diff --stats --progress --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::second first
Prune old archives
Run with --dry-run first to see what would be removed:
borg prune -v --remote-path /usr/local/bin/borg --list --dry-run --keep-daily=7 --keep-weekly 4 --keep-monthly 6 ssh://user@example.com:222/volume1/backups/borg
borg --error prune --keep-weekly 4 --keep-monthly 6 ssh://user@example.com:222/volume1/backups/borg::first
Mount an archive
borg mount --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg /tmp/m_borg
borg umount --remote-path /usr/local/bin/borg /tmp/m_borg
Patterns
| Prefix | Meaning |
|---|---|
pf: |
Path full match: only useful to match full paths |
fm: |
Unix filename pattern matching |
re: |
Regular expression, for example re:^etc\/key |
sh: |
Shell-style pattern, for example sh:**/fs* |
List or search files in an archive
borg list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::full_etc --pattern "pf:etc/fstab"
borg list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::full_etc --pattern "sh:etc/fs*"
Search with a dry-run extraction:
borg extract --dry-run -v --list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::data-2024-01-02 "sh:**/*.jpg"
borg extract --dry-run -v --list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::data-2024-01-02 "fm:*.jpg"
borg extract --dry-run -v --list --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::data-2024-01-02 "re:.*report.*"
Delete an archive
borg delete --dry-run --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg::test
Remove --dry-run to delete for real.
Export the repository key
With repokey encryption the key is stored in the repository. Keep an offline copy:
borg key export --remote-path /usr/local/bin/borg ssh://user@example.com:222/volume1/backups/borg > encrypted-synology-key-backup
borg key export --remote-path /usr/local/bin/borg --paper ssh://user@example.com:222/volume1/backups/borg > encrypted-synology-key-backup.txt
Check versions
borg --version
borg --version --remote-path /usr/local/bin/borg "ssh://user@example.com:222/volume1/backups/borg"
Reference: Backing up to an external server with Borg.