Borgbackup: Difference between revisions

From David's Wiki
Line 64: Line 64:
==Example Scripts==
==Example Scripts==
{{hidden | backup.sh |
{{hidden | backup.sh |
<pre>
<syntaxhighlight lang="bash">
REPOSITORY="my_server:~/Backups/my_backup"
REPOSITORY="my_server:~/Backups/my_backup"
ARCHIVE_NAME="{hostname}-{utcnow}"
ARCHIVE_NAME="{hostname}-{utcnow}"
Line 108: Line 108:
   $BORG_EXEC prune "${BORG_PRUNE_FLAGS[@]}" "${REPOSITORY}"
   $BORG_EXEC prune "${BORG_PRUNE_FLAGS[@]}" "${REPOSITORY}"
fi
fi
</pre>
</syntaxhighlight>
}}
}}


==Resources==
==Resources==
* [https://practical-admin.com/blog/backups-using-borg/ practical-admin backups using borg]
* [https://practical-admin.com/blog/backups-using-borg/ practical-admin backups using borg]

Revision as of 19:01, 29 January 2022

borgbackup is a deduplicating backup software

Installation

Installation

sudo apt install borgbackup

If you want the latest version, you can download a static build from releases or use this backport repo.

Usage

quickstart

Create a repo

borg init

# Create a repo without encryption
borg init --encryption=none ./testrepo

# If you want encryption
borg init --encryption=repokey ./testrepo

Create a backup

borg create

The following will create a backup of ~/src titled Monday to the repo ./testrepo.

borg create --stats --progress ./testrepo::Monday ~/src
Notes
  • Name placeholders: {now}, {utcnow}, {fqdn}, {hostname}, {user}
  • Progress shows (O, C, D, N) which correspond to original size, compressed size, deduplicated size, and number of files processed.
    • Deduplicated size is the additional size consumed on disk after compression and deduplication.
Examples
borg create \
  --stats --progress --show-rc \
  ./testrepo::'{hostname}-daily-{utcnow}' \
  /src

Pruning backups

borg prune

If you're scripting daily, weekly, or monthly backups, you'll probably want to prune old backups.
The command below will keep one backup from today, one backup from last week, and one backup from one month.

borg prune --keep-daily 1 --keep-weekly 1 --keep-monthly 1 remote:~/my_backup

Extract

See extract

borg extract --progress <archive>
  • Note that borgbackup 1.1.11 included in Ubuntu 20.04 has a memory leak when using --progress documented here. Download a newer version of borgbackup.
  • You should extract to an empty folder since borg does not delete existing files in the target folder.

Example Scripts

backup.sh
REPOSITORY="my_server:~/Backups/my_backup"
ARCHIVE_NAME="{hostname}-{utcnow}"
SOURCE_DIR="./"
BACKUP_DIRS=(
  "."
)
BORG_CREATE_FLAGS=(
  "--stats"
  "--progress"
  "-x"
  "--show-rc"
)
BORG_PRUNE_FLAGS=(
  "--keep-daily"
  "3"
  "--keep-weekly"
  "1"
  "--keep-monthly"
  "1"
  #  "--stats"
  "--list"
  "--show-rc"
)
EXCLUSIONS=(
  "-e" "System Volume Information"
  "-e" "\$RECYCLE.BIN"
)
BORG_EXEC="borg"
export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes
export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes
LOCKFILE=/tmp/backup_server.lockfile

exec {lock_fd}>$LOCKFILE || exit 1
flock -n "$lock_fd" || {
  echo "Another instance is running" >&2
  exit 1
}
if [ -d "${SOURCE_DIR}" ]
then
  cd "${SOURCE_DIR}" && \
   $BORG_EXEC create "${BORG_CREATE_FLAGS[@]}" "${EXCLUSIONS[@]}" "${REPOSITORY}"::"${ARCHIVE_NAME}" "${BACKUP_DIRS[@]}" && \
   $BORG_EXEC prune "${BORG_PRUNE_FLAGS[@]}" "${REPOSITORY}"
fi

Resources