Last active
August 29, 2015 14:00
-
-
Save oremj/11161063 to your computer and use it in GitHub Desktop.
mysqldump filter
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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"strings" | |
) | |
func main() { | |
excludeTables := make(map[string]bool) | |
for _, arg := range os.Args { | |
excludeTables[arg] = true | |
} | |
tableName := "" | |
excluded := false | |
inData := false | |
reader := bufio.NewReader(os.Stdin) | |
for { | |
line, err := reader.ReadString('\n') | |
if err != nil { | |
if err == io.EOF { | |
break | |
} | |
log.Fatal(err) | |
} | |
if len(line) > 30 && line[:30] == "-- Table structure for table `" { | |
lastTick := strings.IndexRune(line[30:], '`') + 30 | |
tableName = line[30:lastTick] | |
excluded = excludeTables[tableName] | |
inData = false | |
} else if len(line) > 27 && line[:27] == "-- Dumping data for table `" { | |
inData = true | |
} else if excluded && inData { | |
continue | |
} | |
fmt.Print(line) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment