run_backup_process.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # Trigger the cleanup process
  8. cleanup
  9. exit 1
  10. }
  11. # Function to clean up (unmount and power off HDD)
  12. cleanup() {
  13. echo "Cleaning up..."
  14. echo "Unmounting HDD..."
  15. ./unmount_hdd.sh -f || echo "Failed to unmount HDD"
  16. echo "Turning off HDD power..."
  17. ./power_off_hdd.sh || echo "Failed to power off HDD"
  18. }
  19. # Set trap to call cleanup on script exit or error
  20. trap 'cleanup' EXIT
  21. # Check battery level
  22. echo "Checking battery level..."
  23. ./check_battery.sh || handle_error "check_battery.sh"
  24. # Power on HDD
  25. echo "Turning on HDD power..."
  26. ./power_on_hdd.sh || handle_error "power_on_hdd.sh"
  27. # Delay before mounting
  28. echo "Waiting before mounting HDD..."
  29. sleep 30
  30. # Mount HDD
  31. echo "Mounting HDD..."
  32. ./mount_hdd.sh || handle_error "mount_hdd.sh"
  33. # Run backup
  34. echo "Running backup..."
  35. ./run_backup.sh || handle_error "run_backup.sh"
  36. # Delay before unmounting
  37. echo "Waiting before unmounting HDD..."
  38. sleep 5
  39. # Unmount HDD
  40. echo "Unmounting HDD..."
  41. ./unmount_hdd.sh || handle_error "unmount_hdd.sh"
  42. # Power off HDD
  43. echo "Turning off HDD power..."
  44. ./power_off_hdd.sh || handle_error "power_off_hdd.sh"
  45. echo "Backup process completed successfully."