1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/bin/bash
- cd "$(dirname "$0")"
- # Load environment variables from .env file
- source .env
- # Function to handle errors
- handle_error() {
- echo "Error occurred in script: $1"
- echo "Waiting before unmounting HDD..."
- sleep 10
- # Trigger the cleanup process
- cleanup
- exit 1
- }
- # Function to clean up (unmount and power off HDD)
- cleanup() {
- echo "Cleaning up..."
- echo "Unmounting HDD..."
- ./unmount_hdd.sh -f || echo "Failed to unmount HDD"
- sleep 10
- echo "Turning off HDD power..."
- ./power_off_hdd.sh || echo "Failed to power off HDD"
- }
- # Set trap to call cleanup on script exit or error
- trap 'cleanup' EXIT
- # Check battery level
- echo "Checking battery level..."
- ./check_battery.sh || handle_error "check_battery.sh"
- # Power on HDD
- echo "Turning on HDD power..."
- ./power_on_hdd.sh || handle_error "power_on_hdd.sh"
- # Delay before mounting
- echo "Waiting before mounting HDD..."
- sleep 30
- # Mount HDD
- echo "Mounting HDD..."
- ./mount_hdd.sh || handle_error "mount_hdd.sh"
- # Run backup
- echo "Running backup..."
- ./run_backup.sh || handle_error "run_backup.sh"
- # Log stats to influxdb
- echo "Logging backup to influxdb..."
- ./log_to_influx.sh || handle_error "log_to_influx.sh"
- # Delay before unmounting
- echo "Waiting before unmounting HDD..."
- sleep 5
- # Unmount HDD
- echo "Unmounting HDD..."
- ./unmount_hdd.sh || handle_error "unmount_hdd.sh"
- # Delay before turning off
- echo "Waiting before turning off HDD power..."
- sleep 10
- # Power off HDD
- echo "Turning off HDD power..."
- ./power_off_hdd.sh || handle_error "power_off_hdd.sh"
- echo "Backup process completed successfully."
|