Smart Automated VPS Backup to Backblaze B2R2 with Only 0.5 Months Cost
Detailed guide to set up automatic full server backup to Backblaze B2R2 with optimized cost, ensuring data safety and fast recovery.
Image credit: finnhart · Pixabay Content License
Introduction
Regular data backup is a critical factor in protecting VPS servers from hardware failure, user errors, or cyberattacks. In this guide, we will set up a smart, automated full server backup system to Backblaze B2R2 at an extremely low cost—equivalent to just 0.5 months of VPS service. Backblaze B2R2 is a reliable cloud storage service that supports features like automatic backup, data encryption, and fast recovery.
Prerequisites
- Linux-based VPS (Ubuntu/Debian/CentOS)
- Backblaze B2 account (create at Backblaze B2)
- Access Key and Secret Key from Backblaze B2
- Installed
awscliorb2CLI tool rsyncortarfor data compression and backup
Setting Up Automated Backup with Backblaze B2R2
We will use the Backblaze B2 CLI to sync all server data to B2R2. Follow these steps:
Step 1: Install B2 CLI
Run the following commands to install B2 CLI:
# On Ubuntu/Debian
sudo apt update
sudo apt install -y python3-pip
pip3 install b2
# On CentOS/RHEL
sudo yum install -y python3-pip
pip3 install b2
Step 2: Configure Backblaze B2 Account
Authorize your account using the Access Key and Secret Key:
b2 authorize_account <your-account-id> <your-secret-key>
Step 3: Create Storage Bucket
Create a new bucket for backups:
b2 create_bucket backup-vps-$(date +%Y%m%d) private
Step 4: Create Backup Script
Generate a backup script file:
#!/bin/bash
# backup-vps.sh
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/tmp/backup-$DATE"
B2_BUCKET="backup-vps-$(date +%Y%m%d)"
# Create backup directory
mkdir -p $BACKUP_DIR
# Backup entire server (excluding unnecessary directories)
tar -czf $BACKUP_DIR/backup.tar.gz --exclude="/proc" --exclude="/sys" --exclude="/dev" --exclude="/tmp" --exclude="/run" --exclude="/mnt" --exclude="/media" --exclude="/home/*/.cache" --exclude="/var/log" /
# Upload to Backblaze B2
b2 upload_file $B2_BUCKET $BACKUP_DIR/backup.tar.gz backup-$DATE.tar.gz
# Remove local backup copy
rm -rf $BACKUP_DIR
Step 5: Configure Cron for Automatic Execution
Open the cron editor:
crontab -e
Add the following line to run the backup daily at 2:00 AM:
0 2 * * * /path/to/backup-vps.sh
Cost-Effective Solution
Backblaze B2 charges 0.005 USD/GB/month for storage. For a 100GB VPS, the monthly backup cost is:
- 100GB × 0.005 USD = 0.5 USD/month
- Equivalent to 0.5 months of VPS cost
Verification and Backup Validation
To verify that the backup has been uploaded successfully:
b2 list_files backup-vps-$(date +%Y%m%d)
To restore data:
b2 download_file_by_name backup-vps-$(date +%Y%m%d) backup-20240101_120000.tar.gz /tmp/restore.tar.gz
tar -xzf /tmp/restore.tar.gz -C /restore/
Troubleshooting
- Upload failure to B2: Verify Access Key and Secret Key, ensure the B2 account is active.
- Script fails: Check script execution permissions and correct file path.
- Incomplete data: Ensure no critical directories are excluded in the
tarcommand.
References
- Detailed Guide to Host Multiple Websites on 1 VPS with Docker and Nginx Proxy Manager
- Effective VPS Disk Partitioning and Storage Management Guide for Beginners
- Backblaze B2 Cloud Storage
Related infrastructure & engineering guides: NVMe Cloud VPS for Docker, Nginx & Databases
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
