Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 41 lines (33 sloc) 1.34 KB
#!/usr/bin/env python
import tarfile
import sys
import os
from mbslave import Config, connect_db, parse_name, check_table_exists, fqn
def load_tar(filename, db, config, ignored_tables):
print "Importing data from", filename
tar =, 'r:bz2')
cursor = db.cursor()
for member in tar:
if not'mbdump/'):
name ='/')[1].replace('_sanitised', '')
schema, table = parse_name(config, name)
fulltable = fqn(schema, table)
if table in ignored_tables:
print " - Ignoring", name
if not check_table_exists(db, schema, table):
print " - Skipping %s (table %s does not exist)" % (name, fulltable)
cursor.execute("SELECT 1 FROM %s LIMIT 1" % fulltable)
if cursor.fetchone():
print " - Skipping %s (table %s already contains data)" % (name, fulltable)
print " - Loading %s to %s" % (name, fulltable)
cursor.copy_from(tar.extractfile(member), fulltable)
config = Config(os.path.dirname(__file__) + '/mbslave.conf')
db = connect_db(config)
ignored_tables = set(config.get('TABLES', 'ignore').split(','))
for filename in sys.argv[1:]:
load_tar(filename, db, config, ignored_tables)
Something went wrong with that request. Please try again.