Managing borgbackup effectively is a crucial skill for any system administrator. This tutorial provides step-by-step instructions for deduplication configuration, along with best practices for production environments.
Backup Configuration
Regular maintenance is essential for keeping your borgbackup installation running smoothly. Schedule periodic reviews of log files, disk usage, and security updates to prevent issues before they occur.
# Install and initialize backup tool
sudo apt install -y borgbackup
borgbackup init --repo /backup/repo
# Create first backup
borgbackup backup --repo /backup/repo /etc /home /var/www
# List backups
borgbackup snapshots --repo /backup/repo
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
Important Notes
Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.
- Scale vertically before scaling horizontally
- Start with the minimum required resources
- Use connection pooling for database connections
- Profile before optimizing - measure first
Scheduling Automated Backups
If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.
# Automated backup script: /usr/local/bin/backup.sh
#!/bin/bash
set -euo pipefail
BACKUP_REPO="/backup/repo"
LOG_FILE="/var/log/backup.log"
DATE=$(date +%Y-%m-%d_%H-%M)
echo "[$DATE] Starting backup..." >> $LOG_FILE
# Database dump
mysqldump --all-databases | gzip > /tmp/db-$DATE.sql.gz
# Run backup
borgbackup backup --repo $BACKUP_REPO /etc /home /var/www /tmp/db-$DATE.sql.gz
# Cleanup old backups (keep 30 days)
borgbackup forget --repo $BACKUP_REPO --keep-daily 7 --keep-weekly 4 --keep-monthly 3 --prune
rm /tmp/db-$DATE.sql.gz
echo "[$DATE] Backup completed successfully" >> $LOG_FILE
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
Encryption and Security
The default configuration works well for development environments, but production servers require additional tuning. Pay particular attention to connection limits, timeout values, and logging settings.
# Install and initialize backup tool
sudo apt install -y borgbackup
borgbackup init --repo /backup/repo
# Create first backup
borgbackup backup --repo /backup/repo /etc /home /var/www
# List backups
borgbackup snapshots --repo /backup/repo
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
Performance Considerations
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
- Enable firewall and allow only necessary ports
- Use SSH keys instead of password authentication
- Set up fail2ban for brute force protection
- Keep all software components up to date
Wrapping Up
Following this guide, your borgbackup setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.