Guide to Managing Backups with BorgBackup
1. Installing BorgBackup
BorgBackup can be installed on Linux, macOS, and other Unix-like systems.
On Debian/Ubuntu
1 2 |
sudo apt update sudo apt install borgbackup |
On RedHat/CentOS
1 2 |
sudo yum install epel-release sudo yum install borgbackup |
On macOS with Homebrew
1 |
brew install borgbackup |
On QNAP
To install BorgBackup on QNAP, you need to use the QNAP QTS management system with Entware. Follow these steps:
- Install Entware through the QNAP App Center.
- Connect to the QNAP via SSH and update Entware:
- Install BorgBackup with the following command:
- Verify the installation:
1 |
opkg update |
1 |
opkg install borgbackup |
1 |
borg --version |
2. Creating a New Repository
Before creating a backup, you need to initialize a Borg repository.
1 |
borg init --encryption=repokey /path/to/repository |
You can also use remote repositories via SSH:
1 |
borg init --encryption=repokey user@host:/path/to/remote/repo |
3. Creating a Backup
To create a backup, use the create
command:
1 2 |
borg create --progress --stats /path/to/repository::archive-name \ /path/to/backup |
Example:
1 |
borg create --progress --stats /mnt/backup::bk-2024-01-01 /home/user |
4. Verifying a Backup
You can verify the integrity of a backup with:
1 |
borg check /path/to/repository |
5. Pruning: Managing Retention
To maintain a sensible retention policy, use the prune
command:
1 |
borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=6 /path/to/repository |
This will keep 7 daily backups, 4 weekly backups, and 6 monthly backups.
6. Extracting a Backup
To restore files or directories, use the extract
command:
1 |
borg extract /path/to/repository::archive-name |
You can extract a single file:
1 |
borg extract /path/to/repository::archive-name path/to/file |
You can also mount a backup as a disk on a Linux/Debian/Ubuntu system to explore files:
1 |
borg mount /path/to/repository::archive-name /mount/point |
To unmount:
1 |
borg umount /mount/point |
7. Listing Archives
To list the backups present in the repository:
1 |
borg list /path/to/repository |
8. Connecting to a Remote Repository
To connect to a remote repository and create a backup, use the following syntax:
1 |
borg create --progress --stats user@host:/path/to/remote/repo::archive-name /path/to/backup |
Example:
1 |
borg create --progress --stats user@192.168.1.10:/backups/borg::bk-2024-01-01 /home/user |
9. Useful Commands
- Repository size:
1borg info /path/to/repository
- Remove a specific archive:
1borg delete /path/to/repository::archive-name
Conclusion
BorgBackup is a powerful tool for managing incremental and compressed backups. It can be easily automated with cron jobs or scripts.