Advertisement
Guest User

Untitled

a guest
Aug 25th, 2023
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. ACTION=="add", ATTRS{idVendor}=="0bc2", ATTRS{idProduct}=="2038", RUN+="/root/script/backupZFS.sh"
  2.  
  3.  
  4.  
  5. ----------------------------------------------------------------------------------------------------------------
  6.  
  7. #!/bin/bash
  8.  
  9. # Define source (ZFS) and destination (external HDD) paths
  10. SOURCE=/Orion/Andromeda/
  11. DEST=/media/externalHDD/
  12.  
  13. # Define log file path
  14. LOG_FILE="/var/log/zfs_backup.log"
  15.  
  16. # Get current date in the format YY.MM.DD
  17. CURRENT_DATE=$(date +%Y-%m-%d)
  18.  
  19. # Define backup filename with date
  20. BACKUP_FILENAME="zfs_backup_$CURRENT_DATE"
  21.  
  22. # Mount the external drive if not already mounted
  23. if ! mountpoint -q "$DEST"; then
  24. mount -o rw,uid=1000,gid=1000,user,exec,umask=003 /dev/sdf2 /media/externalHDD/
  25. fi
  26.  
  27. # Run rsync command and redirect output to log file
  28. rsync -avh --progress --delete "$SOURCE" "$DEST/$BACKUP_FILENAME" >> "$LOG_FILE" 2>&1
  29.  
  30. # Get rsync exit status
  31. EXIT_STATUS=$?
  32.  
  33. # Send email notification with simplified message
  34. if [ $EXIT_STATUS -eq 0 ]; then
  35. SUBJECT="ZFS Backup Successful"
  36. MESSAGE="ZFS backup to external HDD completed successfully."
  37. else
  38. SUBJECT="ZFS Backup Failed"
  39. MESSAGE="ZFS backup to external HDD failed."
  40. fi
  41.  
  42. echo "$MESSAGE" | mail -s "$SUBJECT" [email protected]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement