### Install Cygwin Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs necessary development tools and libraries for BorgBackup on Cygwin using the Cygwin installer. ```bash python39 python39-devel python39-setuptools python39-pip python39-wheel python39-virtualenv libssl-devel liblz4-devel binutils gcc-g++ git make openssh ``` -------------------------------- ### Install openSUSE Build Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs BorgBackup build dependencies on openSUSE using zypper. ```bash sudo zypper source-install --build-deps-only borgbackup ``` -------------------------------- ### Install BorgBackup via Pip Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs the latest stable release of BorgBackup from PyPI into the activated virtual environment. ```bash pip install borgbackup ``` -------------------------------- ### Install BorgBackup Man Pages Locally Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs BorgBackup man pages locally after a manual pip installation. This involves cloning the repository, copying man files, and updating the man page cache. ```bash # get borg from github git clone https://github.com/borgbackup/borg.git # Install the files with proper permissions install -D -m 0644 borg/docs/man/borg*.1* $HOME/.local/share/man/man1/borg.1 # Update the man page cache mandb ``` -------------------------------- ### Install Borg Binary on Linux Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Copies the downloaded Borg binary to a system-wide location, sets ownership, and makes it executable. This is for installing a standalone binary. ```bash sudo cp borg-linux64 /usr/local/bin/borg sudo chown root:root /usr/local/bin/borg sudo chmod 755 /usr/local/bin/borg ``` -------------------------------- ### Install BorgBackup Development Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs development dependencies for BorgBackup from lock files within the cloned repository. Optionally installs documentation build dependencies. ```bash cd borg pip install -r requirements.d/development.lock.txt pip install -r requirements.d/docs.txt # optional, to build the docs ``` -------------------------------- ### Install Black and Check Formatting Source: https://github.com/borgbackup/borg/blob/master/docs/development.rst Install the required Black version and use it to check code formatting before committing. This ensures consistency and avoids CI failures. ```bash pip install -r requirements.d/codestyle.txt ``` ```bash black --check . ``` -------------------------------- ### Ansible Playbook for Backup Server Setup Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/central-backup-server.rst An Ansible playbook snippet to configure the backup server, including user creation, directory setup, and SSH key management. ```yaml - hosts: backup01.srv.local vars: user: backup group: backup home: /home/backup pool: "{{ home }}/repos" auth_users: - host: johndoe.clnt.local key: "{{ lookup('file', '/path/to/keys/johndoe.clnt.local.pub') }}" ``` -------------------------------- ### Start Automatic Backup Service Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/automated-local.rst Manually starts the automatic backup service. Use --no-block to allow the command to return immediately. ```bash systemctl start --no-block automatic-backup ``` -------------------------------- ### Install Fedora Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs Python 3, development headers, and required libraries for BorgBackup on Fedora systems. ```bash sudo dnf install python3 python3-devel python3-pip python3-virtualenv \ libacl-devel \ openssl-devel \ lz4-devel \ libffi-devel \ pkgconf sudo dnf install gcc gcc-c++ redhat-rpm-config sudo dnf install fuse-devel fuse # needed for llfuse sudo dnf install fuse3-devel fuse3 # needed for pyfuse3 ``` -------------------------------- ### Install Python with Pyenv and Create Virtual Environment Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs a specific Python version (e.g., 3.11.0) using pyenv, sets it as the global and local version, and then creates and activates a virtual environment using that Python version. ```bash pyenv install 3.11.0 # minimum, preferably use something more recent! pyenv global 3.11.0 pyenv local 3.11.0 virtualenv --python=${pyenv which python} borg-env source borg-env/bin/activate # always before using! ``` -------------------------------- ### Install openSUSE Specific Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs Python 3, development libraries, and optional packages like llfuse on openSUSE. ```bash sudo zypper install python3 python3-devel \ libacl-devel openssl-devel liblz4-devel \ libffi-devel \ python3-Cython python3-Sphinx python3-msgpack-python python3-pkgconfig pkgconf \ python3-pytest python3-setuptools python3-setuptools_scm \ python3-sphinx_rtd_theme gcc gcc-c++ sudo zypper install python3-llfuse # llfuse ``` -------------------------------- ### Install Debian/Ubuntu Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs Python 3, development headers, and necessary libraries for BorgBackup on Debian-based systems. ```bash sudo apt-get install python3 python3-dev python3-pip python3-virtualenv \ libacl1-dev \ libssl-dev \ liblz4-dev \ libffi-dev \ build-essential pkg-config sudo apt-get install libfuse-dev fuse # needed for llfuse sudo apt-get install libfuse3-dev fuse3 # needed for pyfuse3 ``` -------------------------------- ### Install BorgBackup with FUSE Support via Pip Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs BorgBackup along with optional FUSE support (llfuse or pyfuse3) from PyPI into the activated virtual environment. ```bash pip install borgbackup[llfuse] # to use llfuse pip install borgbackup[pyfuse3] # to use pyfuse3 ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/borgbackup/borg/blob/master/CONTRIBUTING.md Installs necessary packages for development using pip. Ensure you have activated a virtual environment first. ```bash pip install -r requirements.d/development.lock.txt ``` -------------------------------- ### Repository Data Structure Example Source: https://github.com/borgbackup/borg/blob/master/docs/internals/data-structures.rst Illustrates the basic structure of a Borg repository's data, including item keys, configuration, and archive metadata. ```python { 'item_keys': ['acl_access', 'acl_default', ...], 'config': {}, 'archives': { '2017-05-05-system-backup': { 'id': b'<32 byte binary object ID>', 'time': '2017-05-05T12:42:22.942864', }, }, } ``` -------------------------------- ### Build Standalone Borg Binary with PyInstaller Source: https://github.com/borgbackup/borg/blob/master/docs/development.rst Install PyInstaller and then use it to create a single, self-contained executable for the Borg platform. This binary will not have external dependencies. ```bash pip install pyinstaller # or git checkout master pyinstaller -F -n borg-PLATFORM borg/__main__.py for file in dist/borg-*; do gpg --armor --detach-sign $file; done ``` -------------------------------- ### Build HTML Documentation with Sphinx Source: https://github.com/borgbackup/borg/blob/master/docs/development.rst Builds the HTML version of the documentation using Sphinx. Requires Sphinx to be installed. ```bash pip install -r requirements.d/docs.txt cd docs/ make html ``` -------------------------------- ### Start borg serve with socat on borg-server Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/pull-backup.rst This command starts the 'borg serve' process on the backup server and uses socat to make its standard input and output available via a UNIX domain socket, ready for a pull backup. ```bash borg-server:~$ socat UNIX-LISTEN:/run/borg/reponame.sock,fork EXEC:"borg serve --restrict-to-path /path/to/repo" ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/borgbackup/borg/blob/master/CONTRIBUTING.md Sets up pre-commit hooks to automatically check code style and quality before each commit. This helps maintain code consistency. ```bash pre-commit install ``` -------------------------------- ### Prune Archives Matching a Pattern Source: https://github.com/borgbackup/borg/blob/master/docs/usage/prune.rst Use archive name patterns to select a subset of archives for pruning. This example keeps the last 7 daily and 4 weekly archives for all archives starting with the hostname followed by a hyphen. ```bash $ borg prune -v --list --keep-daily=7 --keep-weekly=4 -a 'sh:{hostname}-*' ``` -------------------------------- ### Initialize Borg Repository (Full Path - Demonstration) Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/central-backup-server.rst Demonstrates initializing a Borg repository with a full path. This is for demonstration and not recommended for practice. ```shell borg init ssh://backup@backup01.srv.local/home/backup/repos/johndoe.clnt.local/pictures ``` -------------------------------- ### Ansible Playbook for Backup Server Setup Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/central-backup-server.rst This Ansible playbook configures the backup server by installing Borg, setting up a dedicated backup user, and managing SSH authorized keys for client access. Ensure the SSH key paths are correct for your environment. ```yaml - host: web01.clnt.local key: "{{ lookup('file', '/path/to/keys/web01.clnt.local.pub') }}" - host: app01.clnt.local key: "{{ lookup('file', '/path/to/keys/app01.clnt.local.pub') }}" tasks: - package: name=borg state=present - group: name="{{ group }}" state=present - user: name="{{ user }}" shell=/bin/bash home="{{ home }}" createhome=yes group="{{ group }}" groups= state=present - file: path="{{ home }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory - file: path="{{ home }}/.ssh" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory - file: path="{{ pool }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory - authorized_key: user="{{ user }}" key="{{ item.key }}" key_options='command="cd {{ pool }}/{{ item.host }};borg serve --restrict-to-path {{ pool }}/{{ item.host }}",restrict' with_items: "{{ auth_users }}" - file: path="{{ home }}/.ssh/authorized_keys" owner="{{ user }}" group="{{ group }}" mode=0600 state=file - file: path="{{ pool }}/{{ item.host }}" owner="{{ user }}" group="{{ group }}" mode=0700 state=directory with_items: "{{ auth_users }}" ``` -------------------------------- ### Create Archive with Logging Source: https://github.com/borgbackup/borg/blob/master/docs/usage/general.rst This example demonstrates how to create a Borg archive, showing the version, listing files, and displaying the return code. It's useful for verifying archive creation and content. ```bash # Create an archive and log: borg version, files list, return code $ borg -r /path/to/repo create --show-version --list --show-rc my-files files ``` -------------------------------- ### Prepare Borg binary and chroot into client filesystem Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/pull-backup.rst This snippet demonstrates copying the Borg binary into the mounted client filesystem and then mounting essential system directories before chrooting. This ensures Borg is available within the chroot environment and prepares it for backup operations. ```bash # Make borg executable available. cp /usr/local/bin/borg /tmp/sshfs/usr/local/bin/borg # Mount important system directories and enter chroot. cd /tmp/sshfs for i in dev proc sys; do mount --bind /$i $i; done chroot /tmp/sshfs ``` -------------------------------- ### Borg Encryption Process Example Source: https://github.com/borgbackup/borg/blob/master/docs/internals/security.rst Shows the steps involved in encrypting data, including deriving an ID via MAC, compressing data, constructing a header, and performing AEAD encryption. ```python id = MAC(id_key, data) compressed = compress(data) header = type-byte || 00h || message_iv || sessionid aad = id || header message_iv++ encrypted, auth_tag = AEAD_encrypt(session_key, message_iv, compressed, aad) authenticated = header || auth_tag || encrypted ``` -------------------------------- ### Salt State for Borg Backup Installation Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/central-backup-server.rst This Salt state installs Borg backup and its dependencies on a Debian system using pip. It ensures all necessary development libraries and tools are present before installing the package. ```yaml Install borg backup from pip: pkg.installed: - pkgs: - python3 - python3-dev - python3-pip - python-virtualenv - libssl-dev - openssl - libacl1-dev - libacl1 - build-essential - libfuse-dev - fuse - pkg-config pip.installed: - pkgs: ["borgbackup"] - bin_env: /usr/bin/pip3 ``` -------------------------------- ### Build Usage Documentation Source: https://github.com/borgbackup/borg/blob/master/docs/development.rst Generates the usage documentation from command line parsers. This command should be run when command line interfaces change. ```bash python scripts/make.py build_usage ``` -------------------------------- ### Install FreeBSD Dependencies Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs Python 3, pkgconf, OpenSSL, liblz4, FUSE libraries, and Git on FreeBSD. ```bash pkg install -y python3 pkgconf pkg install openssl pkg install liblz4 pkg install fusefs-libs # needed for llfuse pkg install -y git python3 -m ensurepip # to install pip for Python3 ``` -------------------------------- ### Initialize Borg Repository Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/automated-local.rst Initializes a new Borg repository on the mounted backup drive. Ensure the target path and encryption options are correctly specified. ```bash borg init --encryption ... /mnt/backup/borg-backups/backup.borg ``` -------------------------------- ### Install BorgBackup with llfuse on macOS Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs BorgBackup with FUSE support using pip, configuring pkg-config for OpenSSL. ```bash PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" pip install borgbackup[llfuse] ``` -------------------------------- ### Install macFUSE via Homebrew Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs macFUSE on macOS using Homebrew, required for mounting backup archives. ```bash brew install --cask macfuse ``` -------------------------------- ### Initialize Borg Repository via SSH Agent Forwarding Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/pull-backup.rst Initiate a Borg repository on a remote server using an SSH agent and a dedicated client key. This example demonstrates loading the key, executing the 'borg init' command with passphrase, and cleaning up the agent. ```bash (eval $(ssh-agent) > /dev/null ssh-add -q ~/.ssh/borg-client_key echo 'your secure borg key passphrase' | \ ssh -A -o StrictHostKeyChecking=no borgc@borg-client "BORG_PASSPHRASE=\$(cat) borg --rsh 'ssh -o StrictHostKeyChecking=no' init --encryption repokey ssh://borgs@borg-server/~/repo" kill "${SSH_AGENT_PID}") ``` -------------------------------- ### Install Windows Dependencies with MSYS2 Script Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Executes a script within the UCRT64 environment in MSYS2 to install BorgBackup dependencies. ```bash ./scripts/msys2-install-deps ``` -------------------------------- ### Initialize Remote Repository via SSHFS Source: https://github.com/borgbackup/borg/blob/master/docs/quickstart.rst Initialize a remote repository by mounting the remote filesystem using sshfs, then creating the repository locally. ```bash $ sshfs user@hostname:/path/to /path/to $ borg -r /path/to/repo repo-create ... $ fusermount -u /path/to ``` -------------------------------- ### Install macOS Development Dependencies with Brewfile Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Installs Python 3 and other development requirements from a Brewfile in the Borg git repository. ```bash brew install python@3.11 # can be any supported python3 version brew bundle install # install requirements from borg repo's ./Brewfile pip3 install virtualenv ``` -------------------------------- ### Initialize Remote Repository via SSH (rest://) Source: https://github.com/borgbackup/borg/blob/master/docs/quickstart.rst Initialize a remote repository using the rest:// protocol over SSH. Borg runs 'borg serve --rest' on the remote host. ```bash $ borg -r rest://user@hostname:port/path/to/repo repo-create ... ``` -------------------------------- ### Install Borg in Editable Mode Source: https://github.com/borgbackup/borg/blob/master/CONTRIBUTING.md Installs the BorgBackup package in editable mode, allowing for direct code changes to be reflected without reinstallation. ```bash pip install -e . ``` -------------------------------- ### Create a Borg Repository Source: https://github.com/borgbackup/borg/blob/master/docs/quickstart.rst Initializes a new Borg repository at the specified path. This command must be run before any archives can be created. ```bash borg init --encryption=repokey /path/to/repository ``` -------------------------------- ### Import GPG Public Key Source: https://github.com/borgbackup/borg/blob/master/docs/support.rst Import the BorgBackup release signing GPG public key into your local GPG keystore using its full fingerprint. This is necessary for verifying release signatures. ```bash gpg --recv-keys "6D5B EF9A DD20 7580 5747 B70F 9F88 FB52 FAF7 B393" ``` -------------------------------- ### Basic Archive Creation Source: https://github.com/borgbackup/borg/blob/master/docs/usage/create.rst Create a backup archive named 'my-documents' from the '~/Documents' directory. This is the most basic usage of the command. ```bash # Backup ~/Documents into an archive named "my-documents" $ borg create my-documents ~/Documents ``` ```bash # same, but list all files as we process them $ borg create --list my-documents ~/Documents ``` -------------------------------- ### Install Black for Code Formatting Source: https://github.com/borgbackup/borg/blob/master/CONTRIBUTING.md Installs the Black code formatter, which is used for automated code formatting. This ensures a consistent style across the project. ```bash pip install -r requirements.d/codestyle.txt ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/borgbackup/borg/blob/master/docs/installation.rst Sets up a Python virtual environment named 'borg-env' using virtualenv and activates it for isolated package management. ```bash virtualenv --python=python3 borg-env source borg-env/bin/activate ``` -------------------------------- ### Start SSH Agent Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/pull-backup.rst Starts the SSH agent in the background and exports the necessary environment variables to the current shell session. This is a prerequisite for using ssh-add. ```bash eval $(ssh-agent) > /dev/null ``` -------------------------------- ### Borg Serve Restriction Example Source: https://github.com/borgbackup/borg/blob/master/docs/deployment/central-backup-server.rst Example of restricting Borg serve to a specific path for a client. This command is typically configured in the SSH authorized_keys file. ```shell command="cd /home/backup/repos/; borg serve --restrict-to-path /home/backup/repos/", restrict ``` -------------------------------- ### Automate Backups with a Script Source: https://github.com/borgbackup/borg/blob/master/docs/quickstart.rst An example bash script to automate daily backups for a machine. It includes creating a repository (if it doesn't exist), creating an archive, pruning old archives, and compacting the repository. Ensure this script is run as root. ```bash #!/bin/bash # Configuration export BORG_REPO='/borg/repo' export BORG_PASSPHRASE='your_secret_passphrase' # Source directory to back up SOURCE_DIR='/home/user/data' # Archive name format (e.g., myhost-YYYY-MM-DDTHH:MM:SS) ARCHIVE_NAME="$(hostname)-$(date +%Y-%m-%dT%H:%M:%S)" # Check if repository exists, create if not if ! borg list "$BORG_REPO" > /dev/null 2>&1; then echo "Repository does not exist. Creating..." borg init --encryption=repokey "$BORG_REPO" fi # Create the archive echo "Creating archive: $ARCHIVE_NAME" borg create --stats --progress --compression lz4 "$BORG_REPO::$ARCHIVE_NAME" "$SOURCE_DIR" # Prune old archives (keep last 7 daily, 4 weekly, 6 monthly) echo "Pruning old archives..." borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=6 "$BORG_REPO" # Compact the repository to reclaim space echo "Compacting repository..." borg compact "$BORG_REPO" # Unset passphrase for security unset BORG_PASSPHRASE echo "Backup complete." ```