Skip to content

Instantly share code, notes, and snippets.

@juniorplenty
Last active August 29, 2015 14:07
Show Gist options
  • Save juniorplenty/409cf5d2a086c0b3c852 to your computer and use it in GitHub Desktop.
Save juniorplenty/409cf5d2a086c0b3c852 to your computer and use it in GitHub Desktop.
Archive Impressions
#!/bin/bash
SRCDB=honeydew_production
SRCTABLE=impressions
DSTDB=honeydew_archive_2012
DSTTABLE=impressions
SQL="alter table $DSTDB.$DSTTABLE disable keys"
echo "$SQL"
echo "$SQL" | mysql
SID=3962169320
EID=4727791949
INC=100000
for ((sid=SID; sid<EID; sid+=INC)); do
eid=$((sid+INC))
if ((eid>EID)); then
eid=$EID
fi
SQL="insert into $DSTDB.$DSTTABLE select * from $SRCDB.$SRCTABLE where id>=$sid and id<$eid"
echo "$SQL"
echo "$SQL" | mysql
done
SQL="alter table $DSTDB.$DSTTABLE enable keys"
echo "$SQL"
echo "$SQL" | mysql
echo "DONE"
#!/bin/bash
for year in {2012..2012} ; do
for week in {27..39} ; do
partition="y$year"`printf "w%02d" $week`
echo "alter table honeydew_production.impressions drop partition $partition"
echo "alter table honeydew_production.impressions drop partition $partition" | mysql
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment