Created
January 21, 2015 21:58
-
-
Save kballenegger/e5470a57411c5626d846 to your computer and use it in GitHub Desktop.
Print progress of mysql sync operation.
This file contains 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 | |
PID=$(ps aux | grep mysql-dev-backup-s3 | grep -v grep | awk '{ print $2 }') | |
# for some stupid reason, stat in our vagrant vms takes `-c format` not `-f`... | |
ontrap () { | |
echo | |
exit 0 | |
} | |
trap ontrap SIGINT SIGTERM | |
while true; do | |
line=$( | |
lsof -o0 -o -p $PID | | |
awk ' | |
BEGIN { CONVFMT = "%.2f" } | |
$4 ~ /^[0-9]+r$/ && $7 ~ /^0t/ { | |
offset = substr($7, 3) | |
fname = $9 | |
"stat -c %s '\''" fname "'\''" | getline | |
len = $0 | |
print fname, ":", offset, "/", len, offset / len * 100 "%" | |
} | |
' | |
) | |
/bin/echo -ne "$line"'\r' | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment