Created
July 13, 2022 23:20
-
-
Save c0dyhi11/694b103575814d8e2f2b95b6729dfc30 to your computer and use it in GitHub Desktop.
This script will use rsync to keep data in sync on a loop, and then notify you via a Slack webhook how long each iteration took, and how much data was copied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rsync_source="198.51.60.10:/mnt/tank/dataset/" | |
rsync_dest="/mnt/tank/dataset/" | |
slack_token="UYHJ5E74J/B03QSDR6598/8pW72Fl5OOUoFlj53sIccOi6" | |
get_space="df | grep `echo ${rsync_dest::-1}` | awk '{print \$3}'" | |
export BLOCKSIZE=1024 | |
while true; do | |
before_space=`eval "$get_space"` | |
time_passed=`{ time rsync -aAHX $rsync_source $rsync_dest; } 2>&1 | grep real | awk '{print $2}'` | |
after_space=`eval "$get_space"` | |
data_transfered=`echo $((after_space-before_space))` | |
dt_length=`echo "${#data_transfered}"` | |
x=0 | |
while [ $((dt_length)) -ge 4 ]; do | |
data_transfered=`echo $((data_transfered/1024))` | |
((x=x+1)) | |
dt_length=`echo "${#data_transfered}"` | |
done | |
case $x in | |
0) | |
suffix="KB";; | |
1) | |
suffix="MB";; | |
2) | |
suffix="GB";; | |
3) | |
suffix="TB";; | |
*) | |
suffix="???";; | |
esac | |
curl https://hooks.slack.com/services/$slack_token \ | |
-X POST \ | |
-H 'Content-type: application/json' \ | |
-d "{\"text\":\"Data Migration has copied $data_transfered$suffix in $time_passed\"}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment