There is a download all data option for apps, though you do have to
mirror your java classes in python, which is a pain.


A better option would be to port directly in appengine.  This is
easier if you know all the table names, but I will assume otherwise.



public void transferNS(String nsFrom, String nsTo){
NamespaceManager.set(nsFrom);

//get tables
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
Query q = new Query(Query.KIND_METADATA_KIND).setKeysOnly();
HashSet<String> tables = new HashSet<String>();
for (Entity e :
ds.prepare(q).asIterable(FetchOptions.Builder.withLimit(5000).chunkSize(100))
{
tables.add(e.getKey().getName());
}

//once you have the tables, you need to query them and port them
for (String table : tables){
//set to old namespace for the query
NamespaceManager.set(nsFrom);
q = new Query(table);
//set to new namespace for the copying process
NamespaceManager.set(nsTo);
ArrayList<Entity> copies = new ArrayList<Entity>();
for (Entity e :
ds.prepare(q).asIterable(FetchOptions.Builder.withLimit(500000).chunkSize(1000))
{
Entity copy = e.getKey().getName()==null?new
Entity(table,e.getKey().getId()):new
Entity(table,e.getKey().getName());
copy.setPropertiesFrom(e);
copies.add(copy);
if (copies.size()>250){
ds.put(copies);
copies = new ArrayList<Entity>();
}
}
}
}


Please note, if you run this script, it will probably fail, especially
if there is a lot of data.

A better solution would be to launch a deferred task for each table,
so if there is a transient error, it won't break when 1/2 done and
restart again at the beginning.

Also, if you are moving instead of copying, you will want to delete
the old entities.

If you delete them, then you don't need to launch tasks, as retrying
after 1/2 done will start where it left off, instead of at the
beginning.

If you are just copying, I recommend saving a query on the jobs to
memcache so you can pick up where you left off.

Using asynchronous ds instead of regular ds can also make this far
faster and less costlier to you {instance hours}, but then you have to
keep an ArrayList<Future<List<Key>>> so you can finalize the calls
afterword.

Also note, there is a 30 second time limit on queries, so
using .withLimit(500000) is a little naive.  Far better to break the
task into chunks, but I will leave that to you, since this is your
problem ;-}



What I'm saying is, don't download all of the data to your pc unless
you really need a local copy, or you really like mirroring entity
classes in python.

Do the port in appengine.  Running on localhost will be very easy, but
if you get errors in production, it's because you are trying to do too
much work in a single method / task.

Good luck!


On Nov 24, 7:50 am, "Opcenter [N1] Support" <n...@opcenterllc.com>
wrote:
>  Hi,
>
>  I need to take Backup namespace. I created nsapce1,space2,space3.
>  Now i have to transfer data from One namespace to another. So
>  Can this possible to import Namespace data into out local pc.?
>  I  Used GAE with Java.
>
> Thanks
> Noorul

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to