--- a/tablecopy.py Thu Dec 13 17:15:10 2012 +0100
+++ b/tablecopy.py Mon Dec 17 16:48:12 2012 +0100
@@ -2,6 +2,7 @@
#
# Copy data between tables with same table schema.
#
+# Copies full table, target table must be empty.
# Can copy multiple tables in one run.
# Sorts the tables according to references.
#
@@ -17,20 +18,20 @@
class TableCopyTool(toolbase.SrcDstTablesTool):
def __init__(self):
toolbase.SrcDstTablesTool.__init__(self, name='tablecopy', desc='Table copy tool.')
-
+
self.parser.add_argument('-n', '--no-action', dest='noaction', action='store_true',
help="Do nothing, just print tables to be copied. Useful in combination with --regex.")
self.parser.add_argument('--no-sort', dest='nosort', action='store_true',
help="Do not sort. By default, tables are sorted by foreign key references.")
-
+
self.init()
def main(self):
self.srcconn = self.pgm.get_conn('src')
self.dstconn = self.pgm.get_conn('dst')
-
+
dc = pgdatacopy.PgDataCopy(self.srcconn, self.dstconn)
-
+
if self.args.nosort:
for table in self.tables():
self.copy_table(dc, *table)
@@ -39,7 +40,7 @@
details = dict()
pending = set()
references = dict()
-
+
# build list of all table to be copied (pending) and references map
for table in self.tables():
srcschema, srctable, dstschema, dsttable = table
@@ -47,7 +48,7 @@
details[name] = table
pending.add(name)
references[name] = self.get_references(dstschema, dsttable)
-
+
# copy files with fulfilled references, repeat until all done
while pending:
for name in list(pending):
@@ -69,32 +70,32 @@
print('Copying [%s] %s.%s --> [%s] %s.%s' % (
self.args.src, srcschema, srctable,
self.args.dst, dstschema, dsttable))
-
+
if self.args.noaction:
return
-
+
dc.set_source(srctable, srcschema)
dc.set_destination(dsttable, dstschema)
-
+
try:
dc.check()
except pgdatacopy.TargetNotEmptyError as e:
print(' - error:', str(e))
return
-
+
print(' - read ')
buf = io.BytesIO()
wrapped = ProgressWrapper(buf)
dc.read(wrapped)
data = buf.getvalue()
buf.close()
-
+
print(' - write ')
buf = io.BytesIO(data)
wrapped = ProgressWrapper(buf, len(data))
dc.write(wrapped)
buf.close()
-
+
print(' - analyze ')
dc.analyze()