133 lines
3.1 KiB
Markdown
133 lines
3.1 KiB
Markdown
# 📦 Lubelogger Backup Script
|
||
|
||
This script automates the backup process for **Lubelogger** — a self-hosted, open-source vehicle maintenance records and fuel mileage tracker.
|
||
|
||
## ✅ What It Does
|
||
|
||
- Creates a backup of your Lubelogger database.
|
||
- Stores backups in a local directory.
|
||
- Notifies external systems (like **Uptime Kuma** and **Gotify**) of backup status.
|
||
- Cleans up backups and logs older than a specified retention period.
|
||
|
||
---
|
||
|
||
## ⚙️ Features
|
||
|
||
- **Automated Backup** via the Lubelogger API
|
||
- **Success/Failure Notifications** through Uptime Kuma and Gotify
|
||
- **Detailed Logging** with timestamps
|
||
- **Retention Policy** for auto-cleanup of old files
|
||
|
||
---
|
||
|
||
## 📋 Requirements
|
||
|
||
- **Lubelogger** (accessible API endpoint for backups)
|
||
- **Curl** (for HTTP requests)
|
||
- **Bash** (Linux or Unix-based system)
|
||
- *(Optional)* **Uptime Kuma** for monitoring
|
||
- *(Optional)* **Gotify** for alerting
|
||
|
||
---
|
||
|
||
## 🚀 Setup
|
||
|
||
### 1. Clone the Repository
|
||
|
||
```bash
|
||
git clone https://git.nickhepler.cloud/nick/lubelogger-backup.git
|
||
cd lubelogger-backup-script
|
||
```
|
||
|
||
### 2. Configure Environment Variables
|
||
|
||
Create a `.env` file:
|
||
|
||
```env
|
||
USERNAME=rootUser
|
||
PASSWORD=rootPassword
|
||
BASE_URL=https://lubelogger.mydomain.com
|
||
|
||
BACKUP_DIR=$HOME/lubelogger_backups
|
||
RETENTION_DAYS=7
|
||
BACKUP_TAG=lubelogger-db1
|
||
|
||
# Uptime Kuma (optional)
|
||
UPTIME_KUMA_URL=https://uptime-kuma.example.com
|
||
UPTIME_KUMA_API_KEY=your-uptime-kuma-api-key
|
||
|
||
# Gotify (optional)
|
||
GOTIFY_PUSH_URL=https://push.example.de
|
||
GOTIFY_PUSH_KEY=your-app-token
|
||
```
|
||
|
||
> Make sure your Lubelogger API credentials and URLs are correct.
|
||
> Optional services like Uptime Kuma and Gotify will only be used if their variables are set.
|
||
|
||
### 3. Make the Script Executable
|
||
|
||
```bash
|
||
chmod +x lubelogger_backup.sh
|
||
```
|
||
|
||
### 4. Run the Backup
|
||
|
||
```bash
|
||
./lubelogger_backup.sh
|
||
```
|
||
|
||
### 5. Automate via Cron (Optional)
|
||
|
||
To schedule daily backups at 2 AM:
|
||
|
||
```bash
|
||
0 2 * * * /path/to/lubelogger_backup.sh
|
||
```
|
||
|
||
---
|
||
|
||
## 🔍 How It Works
|
||
|
||
1. **Triggers** a backup via Lubelogger’s `/api/makebackup`
|
||
2. **Downloads** the backup `.zip` from the returned URL
|
||
3. **Sends** check-in to Uptime Kuma (if configured)
|
||
4. **Sends** error notification via Gotify (if any failures)
|
||
5. **Generates** a timestamped log file
|
||
6. **Deletes** backups and logs older than `RETENTION_DAYS`
|
||
|
||
---
|
||
|
||
## 🖥️ Example Output
|
||
|
||
```bash
|
||
[$(date)] 🔄 Starting Lubelogger backup job
|
||
[$(date)] ✅ Uptime Kuma check-in sent.
|
||
[$(date)] ⬇️ Downloading backup from https://lubelogger.mydomain.com/api/backup/download/abc123
|
||
[$(date)] ✅ Backup saved to /path/to/backup/backup_2025-04-25_14-30-00.zip
|
||
[$(date)] 🧹 Cleaning up old backups/logs older than 7 days
|
||
[$(date)] ✅ Backup job finished
|
||
```
|
||
|
||
---
|
||
|
||
## 🧰 Troubleshooting
|
||
|
||
### Uptime Kuma
|
||
- Confirm `UPTIME_KUMA_URL` and `API_KEY` are correct
|
||
- Ensure check-in monitoring is configured
|
||
|
||
### Gotify
|
||
- Validate push token and URL
|
||
- Confirm your Gotify server is reachable and running
|
||
|
||
### Permissions
|
||
- Ensure `lubelogger_backup.sh` is executable
|
||
- Verify `BACKUP_DIR` exists and is writable
|
||
|
||
---
|
||
|
||
## 📄 License
|
||
|
||
Licensed under the **GNU General Public License v3.0**.
|
||
See the [LICENSE](LICENSE) file for full details.
|