What You’ll Need
- A server or device to act as the backup source.
- BorgBackup installed on the source.
- Rclone for cloud storage synchronization.
- A cloud storage account (e.g., Google Drive, AWS S3, Backblaze).
Step 1: Install BorgBackup
-
Update and install BorgBackup:
sudo apt update && sudo apt install -y borgbackup
-
Verify the installation:
borg --version
Step 2: Initialize a Borg Repository
-
Create a directory for backups:
mkdir -p ~/backups/borg
-
Initialize the Borg repository:
borg init --encryption=repokey ~/backups/borg
- Replace
~/backups/borg
with the desired repository path. - Enter a secure passphrase when prompted.
- Replace
Step 3: Create a Backup Script
-
Create a script for automated backups:
nano ~/backup.sh
-
Add the following script content:
#!/bin/bash TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") REPO=~/backups/borg borg create --progress --stats $REPO::$TIMESTAMP ~/important-data borg prune --keep-daily=7 --keep-weekly=4 --keep-monthly=6 $REPO
- Replace
~/important-data
with the path to the data you want to back up. - Adjust the
prune
options to fit your retention policy.
- Replace
-
Make the script executable:
chmod +x ~/backup.sh
-
Test the script:
~/backup.sh
Step 4: Install and Configure Rclone
-
Install Rclone:
sudo apt install -y rclone
-
Configure a cloud storage remote:
rclone config
- Follow the prompts to set up your cloud storage provider.
- Name the remote (e.g.,
myremote
) for easy reference.
-
Test the remote configuration:
rclone ls myremote:
Step 5: Automate Cloud Sync with Rclone
-
Modify the backup script to include Rclone:
nano ~/backup.sh
-
Add the following line to sync Borg backups to the cloud:
rclone sync ~/backups/borg myremote:backups/borg --progress
- Replace
myremote:backups/borg
with your desired cloud storage path.
- Replace
-
Save and close the script.
Step 6: Schedule the Backup Script
-
Open the crontab editor:
crontab -e
-
Add the following line to schedule the backup script:
0 2 * * * ~/backup.sh
- This will run the backup script daily at 2:00 AM.
- Adjust the schedule as needed.
Step 7: Verify Backups
-
List Borg backups:
borg list ~/backups/borg
-
Check cloud storage files:
rclone ls myremote:backups/borg
FAQs
Q: Why use Borg and Rclone together?
A: Borg excels at local deduplication and encryption, while Rclone allows seamless synchronization to cloud storage, combining the best of both worlds.
Q: How do I restore data with Borg?
A: Use the following command:
bash borg extract ~/backups/borg::backup_name
Q: Can I encrypt backups in the cloud?
A: Yes, Borg encrypts data before storing it locally. Rclone will upload the encrypted data to the cloud.
Q: How do I check for failed backups?
A: Check the output logs of your script or configure email notifications for cron jobs.
Q: Can I use Rclone without Borg?
A: Yes, Rclone can independently handle backups, but it lacks Borg’s deduplication and encryption features.
Q: How much cloud storage do I need?
A: This depends on the size of your Borg repository and retention policy. Monitor usage with rclone size
.
Q: Is it possible to run backups incrementally?
A: Yes, Borg automatically deduplicates and stores only changed data.
By combining Borg and Rclone, you can automate and secure your backups both locally and in the cloud, ensuring your homelab data is always protected. Happy backing up!