Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Created January 21, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kballenegger/e5470a57411c5626d846 to your computer and use it in GitHub Desktop.
Save kballenegger/e5470a57411c5626d846 to your computer and use it in GitHub Desktop.
Print progress of mysql sync operation.
#!/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