2625cf36d2
- Complete backup script for native Nextcloud (MySQL + files) - Systemd service and timer for daily automated backups at 2 AM - Backblaze B2 integration with secure credential storage - Incremental backup support with 30-day retention - zstd compression for 40-70% storage reduction - Comprehensive documentation and deployment guides - Successfully tested with first backup: 203MB DB + 1.3GB files - Cost-optimized: ~/bin/bash.01-0.02/month for 1.5GB data Deployment Details: - Installed B2 CLI via pipx - Created backup directories at /opt/nextcloud-backup/ - Configured systemd timer for daily execution at 2 AM - First backup verified in B2 bucket: jg-nextcloud - Automated scheduling enabled and tested Documentation includes: - Deployment report with complete setup details - Quick start guide for future deployments - Comprehensive technical reference - Troubleshooting procedures - File manifest and index
223 lines
5.0 KiB
Markdown
223 lines
5.0 KiB
Markdown
# Nextcloud Backblaze B2 Backup - Quick Start Guide
|
|
|
|
## TL;DR Installation (5 minutes)
|
|
|
|
### 1. Install Everything
|
|
```bash
|
|
sudo ./install-nextcloud-backup.sh
|
|
```
|
|
|
|
### 2. Configure B2 Credentials
|
|
```bash
|
|
# Get your B2 Account ID and Application Key from:
|
|
# https://www.backblaze.com/b2/docs/application_keys.html
|
|
|
|
sudo nano /etc/nextcloud-backup/b2-credentials.env
|
|
# Add:
|
|
# B2_ACCOUNT_ID=your_account_id
|
|
# B2_APPLICATION_KEY=your_app_key
|
|
# B2_BUCKET_NAME=nextcloud-backups
|
|
```
|
|
|
|
### 3. Configure Nextcloud Details
|
|
```bash
|
|
sudo nano /opt/nextcloud-backup/.env
|
|
# Edit these for your setup:
|
|
# NEXTCLOUD_DATA_PATH=/srv/docker/nextcloud/data
|
|
# NEXTCLOUD_DB_PASSWORD=your_db_password
|
|
```
|
|
|
|
### 4. Test Backup
|
|
```bash
|
|
# Dry run (no upload)
|
|
sudo DRY_RUN=true /opt/nextcloud-backup/nextcloud-backup-to-backblaze.sh
|
|
|
|
# Real backup
|
|
sudo /opt/nextcloud-backup/nextcloud-backup-to-backblaze.sh incremental
|
|
```
|
|
|
|
### 5. Enable Automated Backups
|
|
```bash
|
|
sudo systemctl enable nextcloud-backup.timer
|
|
sudo systemctl start nextcloud-backup.timer
|
|
```
|
|
|
|
### 6. Verify It's Running
|
|
```bash
|
|
sudo systemctl list-timers nextcloud-backup.timer
|
|
sudo systemctl status nextcloud-backup.timer
|
|
```
|
|
|
|
Done! Your Nextcloud now backs up daily to Backblaze B2.
|
|
|
|
---
|
|
|
|
## Common Commands
|
|
|
|
```bash
|
|
# Manual backup (incremental)
|
|
sudo /opt/nextcloud-backup/nextcloud-backup-to-backblaze.sh incremental
|
|
|
|
# Manual backup (full)
|
|
sudo /opt/nextcloud-backup/nextcloud-backup-to-backblaze.sh full
|
|
|
|
# Check backup status
|
|
sudo /opt/nextcloud-backup/nextcloud-backup-to-backblaze.sh status
|
|
|
|
# View logs
|
|
sudo tail -f /opt/nextcloud-backup/.backups/logs/backup_*.log
|
|
|
|
# Check timer status
|
|
sudo systemctl status nextcloud-backup.timer
|
|
|
|
# View last 50 backup runs
|
|
sudo journalctl -u nextcloud-backup.service -n 50
|
|
|
|
# Live monitor backups
|
|
sudo journalctl -u nextcloud-backup.service -f
|
|
```
|
|
|
|
---
|
|
|
|
## File Locations
|
|
|
|
```
|
|
/opt/nextcloud-backup/
|
|
├── .env # Configuration (edit this!)
|
|
├── .backups/
|
|
│ ├── logs/ # Backup logs
|
|
│ └── .backup-state.json # Last backup info
|
|
├── .backups/logs/backup_*.log # Detailed logs
|
|
└── nextcloud-backup-to-backblaze.sh # Main script
|
|
|
|
/etc/nextcloud-backup/
|
|
└── b2-credentials.env # B2 API credentials (keep secret!)
|
|
|
|
/etc/systemd/system/
|
|
├── nextcloud-backup.service # Backup service
|
|
└── nextcloud-backup.timer # Scheduler
|
|
```
|
|
|
|
---
|
|
|
|
## What Gets Backed Up?
|
|
|
|
✅ **All Nextcloud files** - Documents, photos, videos, etc.
|
|
✅ **Database** - All settings, users, sharing info
|
|
✅ **Compressed** - Smaller files = lower costs
|
|
✅ **Incremental** - Only changed files daily (faster)
|
|
|
|
---
|
|
|
|
## Backup Schedule
|
|
|
|
Default: **Daily at 2 AM**
|
|
|
|
To change time, edit: `/etc/systemd/system/nextcloud-backup.timer`
|
|
|
|
Then: `sudo systemctl daemon-reload && sudo systemctl restart nextcloud-backup.timer`
|
|
|
|
---
|
|
|
|
## Storage Costs (Backblaze B2)
|
|
|
|
Typical Nextcloud: 100GB
|
|
After compression: ~30-40GB
|
|
**Monthly cost: $0.18-0.24**
|
|
|
|
---
|
|
|
|
## Restore Instructions
|
|
|
|
### Restore Database
|
|
```bash
|
|
# Find backup ID in B2
|
|
b2 list-file-names nextcloud-backups nextcloud-backups/ | jq
|
|
|
|
# Download
|
|
b2 download-file-by-id nextcloud-backups <FILE_ID> ./db-backup.sql.zst
|
|
|
|
# Restore
|
|
zstd -d db-backup.sql.zst -c | mysql -u root -p nextcloud
|
|
```
|
|
|
|
### Restore Files
|
|
```bash
|
|
# Download
|
|
b2 download-file-by-id nextcloud-backups <FILE_ID> ./files-backup.tar.zst
|
|
|
|
# Extract
|
|
mkdir /tmp/restore && tar --zstd -xf files-backup.tar.zst -C /tmp/restore
|
|
|
|
# Copy back
|
|
cp -r /tmp/restore/srv/docker/nextcloud/data/* /srv/docker/nextcloud/data/
|
|
```
|
|
|
|
---
|
|
|
|
## Troubleshooting
|
|
|
|
### Backup fails immediately
|
|
```bash
|
|
# Check logs
|
|
sudo tail -100 /opt/nextcloud-backup/.backups/logs/backup_*.log
|
|
|
|
# Check B2 auth
|
|
b2 account-info
|
|
|
|
# Verify paths
|
|
sudo ls -la /srv/docker/nextcloud/data
|
|
```
|
|
|
|
### B2 authentication error
|
|
```bash
|
|
# Clear cached auth
|
|
rm ~/.b2_account_info
|
|
|
|
# Re-authenticate
|
|
b2 authorize-account YOUR_ACCOUNT_ID YOUR_APP_KEY
|
|
```
|
|
|
|
### Timer not running
|
|
```bash
|
|
# Check status
|
|
sudo systemctl status nextcloud-backup.timer
|
|
|
|
# Enable it
|
|
sudo systemctl enable nextcloud-backup.timer
|
|
sudo systemctl start nextcloud-backup.timer
|
|
```
|
|
|
|
### Disk space issues
|
|
```bash
|
|
# Check backup dir size
|
|
du -sh /opt/nextcloud-backup/.backups
|
|
|
|
# Reduce retention (fewer days to keep)
|
|
# Edit: /opt/nextcloud-backup/.env
|
|
# BACKUP_RETENTION_DAYS=14
|
|
```
|
|
|
|
---
|
|
|
|
## Security Best Practices
|
|
|
|
1. **Protect B2 credentials** - Limit access to `/etc/nextcloud-backup/`
|
|
2. **Monitor B2 activity** - Check console monthly for unusual uploads
|
|
3. **Test restores** - Practice restoring monthly
|
|
4. **Rotate keys** - Generate new B2 keys annually
|
|
5. **Keep logs** - Monitor for errors in `/opt/nextcloud-backup/.backups/logs/`
|
|
|
|
---
|
|
|
|
## Need Help?
|
|
|
|
See full documentation: `NEXTCLOUD_BACKBLAZE_SETUP.md`
|
|
|
|
Key sections:
|
|
- **Installation Issues** - Dependencies, paths
|
|
- **Backup Not Working** - Database, permissions
|
|
- **Restore Guide** - Full restore procedures
|
|
- **Cost Optimization** - Reduce B2 spending
|
|
- **Advanced Config** - Custom schedules, hooks
|