def archive_deleted_rows(max_rows=None):
 table_to_rows_archived = {}
 total_rows_archived = 0
 meta = MetaData(get_engine(use_slave=True))
 meta.reflect()
 for table in reversed(meta.sorted_tables):
  tablename = table.name
  if ((tablename == 'migrate_version') or tablename.startswith(_SHADOW_TABLE_PREFIX)):
   continue
  rows_archived = _archive_deleted_rows_for_table(tablename, max_rows=(max_rows - total_rows_archived))
  total_rows_archived += rows_archived
  if rows_archived:
   table_to_rows_archived[tablename] = rows_archived
  if (total_rows_archived >= max_rows):
   break
 return table_to_rows_archived

def archive_deleted_rows ( max_rows = None ) : table_to_rows_archived = { } total_rows_archived = 0 meta = MetaData ( get_engine ( use_slave = True ) ) meta . reflect ( ) for table in reversed ( meta . sorted_tables ) : tablename = table . name if ( ( tablename == 'migrate_version' ) or tablename . startswith ( _SHADOW_TABLE_PREFIX ) ) : continue rows_archived = _archive_deleted_rows_for_table ( tablename , max_rows = ( max_rows - total_rows_archived ) ) total_rows_archived += rows_archived if rows_archived : table_to_rows_archived [ tablename ] = rows_archived if ( total_rows_archived >= max_rows ) : break return table_to_rows_archived
move up to max_rows rows from production tables to corresponding shadow tables .