run_backup_process.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # Load environment variables from .env file
  3. source .env
  4. # Function to handle errors
  5. handle_error() {
  6. echo "Error occurred in script: $1"
  7. echo "Waiting before unmounting HDD..."
  8. sleep 10
  9. # Trigger the cleanup process
  10. cleanup
  11. exit 1
  12. }
  13. # Function to clean up (unmount and power off HDD)
  14. cleanup() {
  15. echo "Cleaning up..."
  16. echo "Unmounting HDD..."
  17. ./unmount_hdd.sh -f || echo "Failed to unmount HDD"
  18. echo "Turning off HDD power..."
  19. ./power_off_hdd.sh || echo "Failed to power off HDD"
  20. }
  21. # Set trap to call cleanup on script exit or error
  22. trap 'cleanup' EXIT
  23. # Check battery level
  24. echo "Checking battery level..."
  25. ./check_battery.sh || handle_error "check_battery.sh"
  26. # Power on HDD
  27. echo "Turning on HDD power..."
  28. ./power_on_hdd.sh || handle_error "power_on_hdd.sh"
  29. # Delay before mounting
  30. echo "Waiting before mounting HDD..."
  31. sleep 30
  32. # Mount HDD
  33. echo "Mounting HDD..."
  34. ./mount_hdd.sh || handle_error "mount_hdd.sh"
  35. # Run backup
  36. echo "Running backup..."
  37. ./run_backup.sh || handle_error "run_backup.sh"
  38. # Log stats to influxdb
  39. echo "Logging backup to influxdb..."
  40. ./log_to_influxdb.sh || handle_error "log_to_influxdb.sh"
  41. # Delay before unmounting
  42. echo "Waiting before unmounting HDD..."
  43. sleep 5
  44. # Unmount HDD
  45. echo "Unmounting HDD..."
  46. ./unmount_hdd.sh || handle_error "unmount_hdd.sh"
  47. # Power off HDD
  48. echo "Turning off HDD power..."
  49. ./power_off_hdd.sh || handle_error "power_off_hdd.sh"
  50. echo "Backup process completed successfully."