Wednesday, May 31

Geek

Splitterer

Let's say you have a MySQL backup made using mysqldump -A, which dumps all the databases on the system into a single file. But you only want to restore one of the databases, which consists of about 300KB in the middle of a 1.7GB SQL dump. And you're not sure if you want today's file or yesterday's or the day before's. How do you find the right one? How do you restore it easily?

Answer: dbsplit.py

import sys
 
bakfile=sys.argv[1]
outfile='header.dat'
 
f=open(bakfile,'r')
g=open(outfile,'w')
 
while 1:
  t=f.readline()
  if t[0:20]=='-- Current Database:':
    db=t[22:-2]
    print db
    g=open(db+'.dat','w')
  g.write(t)
Use: python dbsplit.py <filename>

Posted by: Pixy Misa at 12:38 AM | No Comments | Add Comment | Trackbacks (Suck)
Post contains 100 words, total size 1 kb.

Comments are disabled. Post is locked.
41kb generated in CPU 0.04, elapsed 0.2305 seconds.
54 queries taking 0.2063 seconds, 293 records returned.
Powered by Minx 1.1.6c-pink.