well, there are 2 things to look at.
1) You need to be able to import the dal.py module (located in the /gluon
dir) to setup your connection strings
2) just so you know, there are very few important lines of code in that
script... Only the following matter:
# obviously, you will need to import dal....
from gluon.dal import DAL
# Alternatively, you can use __import__ , something like the
following couple of lines:
# add the path to the gluon folder in sys path
sys.path.append(os.path.abspath('./path/to/gluon'))
# next import the module
__import__('dal',globals={}, locals={}, from list['DAL',], level=0)
# now the meat of the cpdb !
# set you SOURCE and TARGET connection strings
source_db = DAL(<set_you_connection_string_to_your_SOURCE_DB_here>)
<-- we assume this instance already exists
other_db = DAL(<set_you_connection_string_to_your_TARGET_DB_here>)
# Now, you can loop through the tables of your SOURCE db and use
*THAT* (along with its fields) to
# define your TARGET tables and fields (this takes care of you DB
model)
for table in source_db:
other_db.define_table(
table._tablename, *[field for field in table])
# next, you want to populate your TARGET DB with the data from your
SOURCE DB
# so the following will dump the data (from SOURCE) as CSV
formatted lines in a file called 'temp.sql'
source_db.export_to_csv_file(open('tmp.sql', 'wb'))
# Now, the reverse needs to happen... the next line will load the
data that was just dumped to temp.sql
# and will import it to you TARGET instance
other_db.import_from_csv_file(open('tmp.sql', 'rb'))
# Finally, you just need to commit the changes in your newly
populated TARGET BD
other_db.commit()
Then, your done.
I hope this helps,
Mart
On Friday, May 9, 2014 5:23:58 PM UTC-7, Ben Lawrence wrote:
>
> Hi,
> How did you get to that stage? I get:
>
> gluon path not found
>
> EXCEPTION: could not make a copy of the database
>
> global name 'DAL' is not defined
>
> On Saturday, July 23, 2011 12:17:22 AM UTC-7, Saurabh Sawant wrote:
>>
>> I am having a hard time migrating data from sqlite to postgres
>>
>> This is the command that I use
>>
>> ./web2py.py -S testapp -M -N -R scripts/cpdb.py -A -f
>> sqlite://applications/testapp/databases/storage.sqlite -y 'sqlite://
>> applications/testapp/databases/storage.sqlite' -Y 'postgres://
>> puser:ppass@localhost/testdb'
>>
>> It says
>>
>> web2py Web Framework
>> Created by Massimo Di Pierro, Copyright 2007-2011
>> Version 1.97.1 (2011-06-26 19:25:44)
>> Database drivers available: SQLite3, pymysql, PostgreSQL
>> EXCEPTION: could not make a copy of the database
>> Failure to connect, tried 5 times:
>> unable to open database file
>>
>> Any idea how to make this work?
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.