Last active
December 14, 2015 03:09
-
-
Save shantanuo/5019161 to your computer and use it in GitHub Desktop.
extract data from binary and upload to remote server using curl.
The text files used for "load data infile" command are tarred and sql commands are gunzipped.
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/sh | |
# call the script as shown below | |
# sh -xv extract.sh "db_name" "2013-02-23 00:00:00" "2013-02-23 01:59:59" | |
# or else it will select yesterday binary by default | |
mystart1=`date -d"1 days ago" +'%Y-%m-%d 00:00:01'` | |
mystop1=`date +'%Y-%m-%d 00:00:00'` | |
mystart=${2:-$mystart1} | |
mystop=${3:-$mystop1} | |
myfile=`date -d"$mystart" +'%b%d'` | |
userpass='-uapplication -plistetim' | |
dbname=`mysqlshow $userpass | egrep -v "(Databases|mysql|test|information_schema|performance_schema|lost)" | awk '{print $2}' | sed '/^$/d'` | |
mydb=${1:-$dbname} | |
rm -rf /increment/ | |
mkdir -p /increment/ | |
cd /increment/ | |
time mysqlbinlog /var/log/mysql/mysql-bin.* --local-load=/increment/ --start-datetime="$mystart" --stop-datetime="$mystop" | gzip > /home/binary.$mydb.$myfile.sql.gz 2> /home/binary_extract.err | |
tar cvfz binary.$mydb.$myfile.txt.tar.gz * | |
time curl -F "file=@/increment/binary.$mydb.$myfile.txt.tar.gz" http://1.2.3.4/upload.php | |
time curl -F "file=@/home/binary.$mydb.$myfile.sql.gz" http://1.2.3.4/upload.php |
Author
shantanuo
commented
Feb 23, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment