Last active
November 22, 2019 20:56
-
-
Save isaaclw/8de2d9a86598ef26b721600b5606c9f0 to your computer and use it in GitHub Desktop.
Copy Differences in block device #perl #hardware #blockdevice
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 | |
dev1=$1 | |
remote=$(echo $2 | cut -d ':' -f 1) | |
dev2=$(echo $2 | cut -d ':' -f 2) | |
ssh -i ~/.ssh/id_rsa $remote " | |
perl -'MDigest::MD5 md5' -ne 'BEGIN{\$/=\1024};print md5(\$_)' $dev2 | lzop -c" | | |
lzop -dc | perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=\1024};$b=md5($_); | |
read STDIN,$a,16;if ($a eq $b) {print "s"} else {print "c" . $_}' $dev1 | lzop -c | | |
ssh -i ~/.ssh/id_rsa $remote "lzop -dc | | |
perl -ne 'BEGIN{\$/=\1} if (\$_ eq\"s\") {\$s++} else {if (\$s) { | |
seek STDOUT,\$s*1024,1; \$s=0}; read ARGV,\$buf,1024; print \$buf}' 1<> $dev2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment