title: How to create and restore a backup from SqlAlchemy?
body: <p>I'm writing a Pylons app, and am trying to create a simple backup system where every table is serialized and tarred up into a single file for an administrator to download, and use to restore the app should something bad happen.</p>
  
  <p>I can serialize my table data just fine using the <a href="https://docs.sqlalchemy.org/en/13/core/serializer.html" rel="nofollow noreferrer">SqlAlchemy serializer</a>, and I can deserialize it fine as well, but I can't figure out how to commit those changes back to the database.</p>
  
  <p>In order to serialize my data I am doing this:</p>
  
  <pre><code>from myproject.model.meta import Session
  from sqlalchemy.ext.serializer import loads, dumps
  q = Session.query(MyTable)
  serialized_data = dumps(q.all())
  </code></pre>
  
  <p>In order to test things out, I go ahead and truncation <code>MyTable</code>, and then attempt to restore using <code>serialized_data</code>:</p>
  
  <pre><code>from myproject.model import meta
  restore_q = loads(serialized_data, meta.metadata, Session)
  </code></pre>
  
  <p>This doesn't seem to do anything... I've tried calling a <code>Session.commit</code> after the fact, individually walking through all the objects in <code>restore_q</code> and adding them, but nothing seems to work.</p>
  
  <p>What am I missing? Or is there a better way to do what I'm aiming for? I don't want to shell out and directly touch the database, since SqlAlchemy supports different database engines.</p>