Guide to Managing Backups with BorgBackup
1. Installing BorgBackup
BorgBackup can be installed on Linux, macOS, and other Unix-like systems.
On Debian/Ubuntu
sudo apt update
sudo apt install borgbackup
On RedHat/CentOS
sudo yum install epel-release
sudo yum install borgbackup
On macOS with Homebrew
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:
opkg update
opkg install borgbackup
borg --version
2. Creating a New Repository
Before creating a backup, you need to initialize a Borg repository.
borg init --encryption=repokey /path/to/repository
You can also use remote repositories via SSH:
borg init --encryption=repokey user@host:/path/to/remote/repo
3. Creating a Backup
To create a backup, use the create
command:
borg create --progress --stats /path/to/repository::archive-name \
/path/to/backup
Example:
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:
borg check /path/to/repository
5. Pruning: Managing Retention
To maintain a sensible retention policy, use the prune
command:
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:
borg extract /path/to/repository::archive-name
You can extract a single file:
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:
borg mount /path/to/repository::archive-name /mount/point
To unmount:
borg umount /mount/point
7. Listing Archives
To list the backups present in the repository:
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:
borg create --progress --stats user@host:/path/to/remote/repo::archive-name /path/to/backup
Example:
borg create --progress --stats user@192.168.1.10:/backups/borg::bk-2024-01-01 /home/user
9. Useful Commands
- Repository size:
borg info /path/to/repository
- Remove a specific archive:
borg 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.