🌐 Overview
ThisBash script automates the backup and version control ofHomebridge andZigbee2MQTT configuration files usingGit, specificallyGitHub, for storage and version tracking. It begins by defining the locations for the log file, repository directory, and source directories for both Homebridge and Zigbee2MQTT. The script then navigates to the repository directory, identifies the latest backup files in the source directories, and copies them to designated directories within the repository. It logs each copy operation with a timestamp.
Following this, the script updates the local Git repository to reflect the latest state of the remote master branch, adds the newly copied backup files to the repository, and checks if there are any changes ready to be committed. If there are, it commits these changes with a timestamped message and pushes the commit to the remote master branch on GitHub. If the file addition fails, it logs an error message. This ensures that both Homebridge and Zigbee2MQTT configurations are backed up locally and securely stored remotely with an up-to-date version history.
Script Execution via CRON
This script has been designed to run automatically via aCRON job on the server, ensuring consistent and unattended backups and synchronization of Homebridge and Zigbee2MQTT configurations to GitHub.