|
@@ -0,0 +1,120 @@
|
|
|
+# Borg Backup Automation
|
|
|
+
|
|
|
+This project automates the process of running Borg backups on a Linux server. It includes scripts for managing external HDD power, mounting and unmounting the HDD, running the backup, and logging the results to InfluxDB.
|
|
|
+
|
|
|
+## Table of Contents
|
|
|
+
|
|
|
+- [Project Structure](#project-structure)
|
|
|
+- [Installation](#installation)
|
|
|
+- [Configuration](#configuration)
|
|
|
+- [Usage](#usage)
|
|
|
+- [Scripts Overview](#scripts-overview)
|
|
|
+- [Contributing](#contributing)
|
|
|
+- [License](#license)
|
|
|
+
|
|
|
+## Project Structure
|
|
|
+
|
|
|
+```
|
|
|
+.
|
|
|
+├── power_on_hdd.sh # Script to power on the external HDD
|
|
|
+├── power_off_hdd.sh # Script to power off the external HDD
|
|
|
+├── mount_hdd.sh # Script to mount the external HDD
|
|
|
+├── unmount_hdd.sh # Script to unmount the external HDD
|
|
|
+├── check_battery.sh # Script to check battery level before running the backup
|
|
|
+├── run_backup.sh # Script to execute the Borg backup
|
|
|
+├── run_backup_process.sh # Main script to automate the backup process
|
|
|
+├── log_to_influx.sh # Script to log the backup results to InfluxDB
|
|
|
+├── grafana_dashboard.json # Example Grafana dashboard for monitoring
|
|
|
+├── .env # Environment variables (ignored by Git)
|
|
|
+├── .env.example # Example environment variables file
|
|
|
+├── .gitignore # Files and directories to be ignored by Git
|
|
|
+└── keys/ # Directory for SSH keys (ignored by Git)
|
|
|
+```
|
|
|
+
|
|
|
+## Installation
|
|
|
+
|
|
|
+1. **Clone the repository:**
|
|
|
+ ```bash
|
|
|
+ git clone https://github.com/yourusername/borg-backup-automation.git
|
|
|
+ cd borg-backup-automation
|
|
|
+ ```
|
|
|
+
|
|
|
+2. **Set up your environment:**
|
|
|
+ - Copy the example `.env` file:
|
|
|
+ ```bash
|
|
|
+ cp .env.example .env
|
|
|
+ ```
|
|
|
+ - Edit `.env` with your specific configuration.
|
|
|
+
|
|
|
+3. **Ensure all scripts have executable permissions:**
|
|
|
+ ```bash
|
|
|
+ chmod +x *.sh
|
|
|
+ ```
|
|
|
+
|
|
|
+## Configuration
|
|
|
+
|
|
|
+The configuration is managed via the `.env` file. Below are the key variables you need to configure:
|
|
|
+
|
|
|
+- **Home Assistant Details:**
|
|
|
+ - `HA_URL`: URL of your Home Assistant instance.
|
|
|
+ - `HA_TOKEN`: Long-lived access token for Home Assistant.
|
|
|
+ - `HDD_SWITCH_ENTITY`: Home Assistant entity ID for controlling HDD power.
|
|
|
+ - `BATTERY_SENSOR_ENTITY`: Home Assistant entity ID for battery level monitoring.
|
|
|
+ - `MIN_BATTERY_LEVEL`: Minimum battery percentage required to run the backup.
|
|
|
+
|
|
|
+- **Server Details:**
|
|
|
+ - `SERVER_USER`: SSH user for the remote server.
|
|
|
+ - `SERVER_IP`: IP address of the remote server.
|
|
|
+ - `SSH_KEY`: Path to the SSH private key.
|
|
|
+ - `SSH_PORT`: SSH port (default: 22).
|
|
|
+
|
|
|
+- **HDD Mount Details:**
|
|
|
+ - `HDD_DEVICE`: Device path for the external HDD (e.g., `/dev/sdb1`).
|
|
|
+ - `MOUNT_POINT`: Mount point for the external HDD (e.g., `/mnt/external_hdd`).
|
|
|
+
|
|
|
+- **Borg Backup Details:**
|
|
|
+ - `REPOSITORY`: Path to the Borg backup repository on the mounted HDD.
|
|
|
+ - `SOURCE_DIRECTORIES`: Directories to back up.
|
|
|
+ - `PASSPHRASE`: Passphrase for the Borg repository.
|
|
|
+
|
|
|
+- **Logging Details:**
|
|
|
+ - `INFLUXDB_URL`: URL of your InfluxDB instance.
|
|
|
+ - `INFLUXDB_ORG`: Organization name for InfluxDB.
|
|
|
+ - `INFLUXDB_BUCKET`: InfluxDB bucket for storing backup logs.
|
|
|
+ - `INFLUXDB_TOKEN`: Authentication token for InfluxDB.
|
|
|
+
|
|
|
+## Usage
|
|
|
+
|
|
|
+Run the main backup process script:
|
|
|
+
|
|
|
+```bash
|
|
|
+./run_backup_process.sh
|
|
|
+```
|
|
|
+
|
|
|
+This script will:
|
|
|
+
|
|
|
+1. Check the battery level.
|
|
|
+2. Power on the external HDD.
|
|
|
+3. Mount the external HDD.
|
|
|
+4. Run the Borg backup.
|
|
|
+5. Log the backup results to InfluxDB.
|
|
|
+6. Unmount and power off the external HDD.
|
|
|
+
|
|
|
+## Scripts Overview
|
|
|
+
|
|
|
+- **power_on_hdd.sh:** Turns on the external HDD via Home Assistant.
|
|
|
+- **power_off_hdd.sh:** Turns off the external HDD via Home Assistant.
|
|
|
+- **mount_hdd.sh:** Mounts the external HDD to a specified mount point.
|
|
|
+- **unmount_hdd.sh:** Unmounts the external HDD.
|
|
|
+- **check_battery.sh:** Checks the battery level and exits if it’s below the specified threshold.
|
|
|
+- **run_backup.sh:** Executes the Borg backup using the configured source directories and repository.
|
|
|
+- **log_to_influx.sh:** Logs backup statistics to InfluxDB.
|
|
|
+- **run_backup_process.sh:** Main automation script that ties all the steps together.
|
|
|
+
|
|
|
+## Contributing
|
|
|
+
|
|
|
+Contributions are welcome! Please submit pull requests or open issues to suggest changes or report bugs.
|
|
|
+
|
|
|
+## License
|
|
|
+
|
|
|
+This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|