def estimate_backup_size(self): # PITA # Look all all the filtering crap in Maatkit and try to get as close # as possible to how Maatkit finds tables # options: # databases,ignoredb,dbregex # tables,ignoretbl,tblregex # ignoreengine databases = self.config.lookup('maatkit.databases') ignoredb = self.config.lookup('maatkit.ignoredb') dbregex = self.config.lookup('maatkit.dbregex') tables = self.config.lookup('maatkit.tables') ignoretbl = self.config.lookup('maatkit.ignoretbl') tblregex = self.config.lookup('maatkit.tblregex') ignoreengine = self.config.lookup('maatkit.ignoreengine') if self.dry_run: if 'password' in self.my_cnf['client']: password = self.my_cnf['client'].pop('password') self.my_cnf['client']['passwd'] = password mysqlclient = MySQLClient(**dict(self.my_cnf['client'].items())) else: mysqlclient = MySQLClient(read_default_file=self.my_cnf.path) estimated_size = 0 for db in mysqlclient.show_databases(): for info in mysqlclient.show_table_status(db): tbl = info['name'] qtbl = db + '.' + tbl if databases and db not in databases: continue if ignoredb and db in ignoredb: continue if dbregex and not re.search(dbregex, db): continue if tables and (tbl not in tables or qtbl not in tables): continue if ignoretbl and (tbl in ignoretbl or qtbl in ignoretbl): continue if tblregex and not re.search(tblregex, qtbl): continue if ignoreengine and info['engine'] in ignoreengine: continue estimated_size += int(info['data_length'] or 0) + \ int(info['index_length'] or 0) return estimated_size
import load_it from holland.lib.mysql.client import MySQLClient client = MySQLClient(read_default_group='client') print client.encode_as_filename('foo/bar') print client.encode_as_filename('foo.bar')