def restore(self):
        """use the self.directory to restore a db

        NOTE -- this will only restore a database dumped with one of the methods
        of this class
        """
        sql_files = []
        for root, dirs, files in os.walk(self.directory):
            for f in files:
                if f.endswith(".sql.gz"):
                    path = os.path.join(self.directory, f)
                    self._run_cmd(["gunzip", path])
                    sql_files.append(f.rstrip(".gz"))

                elif f.endswith('.sql'):
                    sql_files.append(f)

        sql_files.sort() # we want to go in the order the tables were dumped
        r = re.compile('\d{3,}_([^\.]+)')
        for f in sql_files:
            path = os.path.join(self.directory, f)
            m = r.match(f)
            if m:
                table = m.group(1)
                logger.info('------- restoring table {}'.format(table))

                #psql_args = self._get_args('psql', '-X', '--echo-queries', '-f {}'.format(path))
                psql_args = self._get_args('psql', '-X', '--quiet', '--file={}'.format(path))
                self._run_cmd(psql_args)

                logger.info('------- restored table {}'.format(table))

        return True
def restore ( self ) : sql_files = [ ] for root , dirs , files in os . walk ( self . directory ) : for f in files : if f . endswith ( ".sql.gz" ) : path = os . path . join ( self . directory , f ) self . _run_cmd ( [ "gunzip" , path ] ) sql_files . append ( f . rstrip ( ".gz" ) ) elif f . endswith ( '.sql' ) : sql_files . append ( f ) sql_files . sort ( ) r = re . compile ( '\d{3,}_([^\.]+)' ) for f in sql_files : path = os . path . join ( self . directory , f ) m = r . match ( f ) if m : table = m . group ( 1 ) logger . info ( '------- restoring table {}' . format ( table ) ) psql_args = self . _get_args ( 'psql' , '-X' , '--quiet' , '--file={}' . format ( path ) ) self . _run_cmd ( psql_args ) logger . info ( '------- restored table {}' . format ( table ) ) return True
use the self.directory to restore a db

        NOTE -- this will only restore a database dumped with one of the methods
        of this class