Automated backup script for Lubelogger, a self-hosted vehicle maintenance tracker. Supports notifications via Uptime Kuma and Gotify, with automatic cleanup of old backups and logs. Includes detailed logging, API integration, and cron-friendly setup.
Go to file
2025-04-25 15:38:51 -04:00
LICENSE Initial commit 2025-04-25 09:54:10 -04:00
lubelogger_backup.sh fix(backup): remove -n flag from curl to fix empty response issue 2025-04-25 12:22:59 -04:00
README.md Update README.md 2025-04-25 15:38:51 -04:00

📦 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

git clone https://git.nickhepler.cloud/nick/lubelogger-backup.git
cd lubelogger-backup-script

2. Configure Environment Variables

Create a .env file:

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

chmod +x lubelogger_backup.sh

4. Run the Backup

./lubelogger_backup.sh

5. Automate via Cron (Optional)

To schedule daily backups at 2 AM:

0 2 * * * /path/to/lubelogger_backup.sh

🔍 How It Works

  1. Triggers a backup via Lubeloggers /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

[$(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 file for full details.

❤️ About LubeLogger

LubeLogger is an open-source web-based vehicle maintenance and fuel mileage tracker. Learn more or contribute to the main project here:

🔗 https://github.com/hargata/lubelog