Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ACTION=="add", ATTRS{idVendor}=="0bc2", ATTRS{idProduct}=="2038", RUN+="/root/script/backupZFS.sh"
- ----------------------------------------------------------------------------------------------------------------
- #!/bin/bash
- # Define source (ZFS) and destination (external HDD) paths
- SOURCE=/Orion/Andromeda/
- DEST=/media/externalHDD/
- # Define log file path
- LOG_FILE="/var/log/zfs_backup.log"
- # Get current date in the format YY.MM.DD
- CURRENT_DATE=$(date +%Y-%m-%d)
- # Define backup filename with date
- BACKUP_FILENAME="zfs_backup_$CURRENT_DATE"
- # Mount the external drive if not already mounted
- if ! mountpoint -q "$DEST"; then
- mount -o rw,uid=1000,gid=1000,user,exec,umask=003 /dev/sdf2 /media/externalHDD/
- fi
- # Run rsync command and redirect output to log file
- rsync -avh --progress --delete "$SOURCE" "$DEST/$BACKUP_FILENAME" >> "$LOG_FILE" 2>&1
- # Get rsync exit status
- EXIT_STATUS=$?
- # Send email notification with simplified message
- if [ $EXIT_STATUS -eq 0 ]; then
- SUBJECT="ZFS Backup Successful"
- MESSAGE="ZFS backup to external HDD completed successfully."
- else
- SUBJECT="ZFS Backup Failed"
- MESSAGE="ZFS backup to external HDD failed."
- fi
- echo "$MESSAGE" | mail -s "$SUBJECT" [email protected]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement