Borg Backup

Borg Backup

start new repo

borg init --encryption=repokey /mnt/repo

CREATE

create 1st snapshot

borg create /mnt/repo::$(date +%Y%m%d_%H%M%S) /path/to/stuff_to_back

create backup w compression

borg create --compression lzma,9 /path/to/repo::arch /path/to/stuff_to_back (LZMA compression level 9, 0 is lowest compression 9 is highest)

# compression methods

# lzma, zlib, lz4

dont use compression (faster and less CPU)

borg create --compression none /path/to/repo::<tag> /dir

SHOW

show all snapshots

borg list /mnt/repo

show all files in a snapshot

borg list /mnt/repo::<tag of snapshot>

RESTORE

restore entire repo

borg extract /path/to/repo::<snapshot>

restore only 1 directory

borg extract /mnt/repo::<tag of snapshot> home/username/some_dir

test extraction w/out actually writing to disk

borg extract --dry-run /mnt/repo::<tag>

mount a snapshot as a directory

borg mount /mnt/repo::<tag> /mnt/restored (to unmount: umount /mnt/restored)

PRUNE

prune and keep last 10 days

borg prune --keep-within=10d /path/to/repo

CHECK

# check for corrupt chunks / segments:

borg check -v --repository-only REPO

# repair the repo:

borg check -v --repository-only --repair REPO

# make sure everything is fixed:

borg check -v --repository-only REPO

SCRIPTING

set passphrase in script

export BORG_PASSPHRASE=mypassphrase