Borg client script
Borg Backup Client Script
This bash script is used as a client-side script to perform backups using the BorgBackup tool. The script connects to a remote Borg Backup repository and creates and prunes backups according to the specified retention policy. It utilizes SSH authentication for secure communication with the backup repository.
Script Features
- Sets environment variables for Borg Backup.
- Creates new backups and includes/excludes specified files.
- Removes old backups based on a defined retention policy.
Script Usage
- Set up SSH key authentication for the user running the script. The script uses the specified private key to authenticate with the backup repository.
- Modify the
BORG_REPOvariable to point to the remote backup repository in the format:user@hostname:/path/to/repository. - Customize the
borg_exclusionsandborg_inclusionsarrays to define files/folders to exclude and include in the backup. - Schedule the script to run at regular intervals using a scheduling tool like cron.
Script Details
Environment Setup
This section sets up environment variables for Borg Backup to use during the backup and prune operations.
export BORG_RSH="ssh -i /Users/{{ ansible_user }}/.ssh/borgbackup" export BORG_REPO=borgbackup@Family-Mac-Mini.local:/Users/borgbackup/borgbackup/{{ ansible_hostname }}Backup Operation
This section initiates a new backup operation using the
borg createcommand. It specifies options for filtering, compression, exclusion, and naming of the backup archive.echo "Start backup" borg create \ --list --stats \ --filter AME \ --compression lz4 \ --exclude-caches \ {% for exclude in borg_exclusions %} --exclude '{{ exclude }}' \ {% endfor %} ::'{hostname}-{now}' \ {% for include in borg_inclusions %} '{{ include }}' \ {% endfor %}Pruning Old Backups
This section removes old backups based on the specified retention policy using the
borg prunecommand.echo "Remove old backups" borg prune \ --glob-archives '{hostname}-*' \ --keep-daily 7 \ --keep-weekly 4 \ --keep-monthly 6 \ --keep-yearly 1
This script facilitates the backup process using Borg Backup, allowing you to create and manage backups with a defined retention policy. By configuring the script with appropriate exclusions, inclusions, and repository details, you can ensure the safety and availability of your data.