May 30, 2006

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 02:38 PM | Comments (1) | Add Comment | Trackbacks (Suck)






Processing 0.0, elapsed 0.0067 seconds.
14 queries taking 0.0038 seconds, 21 records returned.
Page size 7 kb.
Powered by Minx 0.8 beta.