Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse config.xml for db parameters, add omero db dump #74

Merged
merged 11 commits into from
Feb 9, 2016

Conversation

manics
Copy link
Member

@manics manics commented Nov 27, 2015

Adds a new --use-db-config flag to omego db ... and omego upgrade --upgradedb .... If omero.db.* properties are already in the OMERO.server config using this flag means you don't need the --db{host,name,user} arguments

e.g. Instead of:
omego upgrade -v --sym OMERO-TEST --upgradedb --dbname name --dbuser user --dbpass pass ...
You can do:
omego upgrade -v --sym OMERO-TEST --upgradedb --use-db-config ...

To backup your existing omero DB (or replace --use-db-config with the old --db* arguments):
omego db dump --serverdir OMERO-TEST --use-db-config -v
If you want to override the dumped filename pass --dumpfile ...
Use -n for a dry-run`

@joshmoore
Copy link
Member

Under what conditions will you not want to use omero.db.* properties if they are in config.xml? i.e would reversing the flag to --no-db-config be the more common case?

@manics
Copy link
Member Author

manics commented Nov 30, 2015

@joshmoore Changed as you suggested. Suggestions on defaults if they're not specified in config.xml or commandline, especially if we eventually encourage externals to use it? At the moment:

  • dbhost: localhost,
  • dbuser: omero
  • dbpass: omero
  • dbname: no default, must be specified (thinking was to reduce chance of accidentally modifying an existing DB)

@joshmoore
Copy link
Member

Defaults make sense since that's what will be used if no bin/omero config set is called. Under what conditions will an existing db be modified, only on upgrade, right?

@manics
Copy link
Member Author

manics commented Nov 30, 2015

Yes, just that it'd be annoying if you inadvertently upgraded to a DEV schema since you couldn't revert to the last release.

@joshmoore
Copy link
Member

Agreed. It's likely too big a change for here, but it just occurs to me (even for our own use) if it would be safer to do:

    $ psql -c "CREATE DATABASE omero52 WITH TEMPLATE omero51 OWNER dbuser;"
    $ bin/omero config set omero.db.name omero52
    $ psql -f sql/psql/OMERO5.2__0/OMERO5.1__0.sql

i.e. non-destructively upgrade unless a flag like --overwrite is passed.

@manics
Copy link
Member Author

manics commented Nov 30, 2015

Issue added #75

@manics
Copy link
Member Author

manics commented Jan 15, 2016

Fixed a bug reported in #69 (comment)

@joshmoore
Copy link
Member

Time to retest?

@manics
Copy link
Member Author

manics commented Jan 21, 2016

It's on @pwalczysko's todo list

@pwalczysko
Copy link
Member

ToDo today.

@pwalczysko
Copy link
Member

It seems that #69 (comment) is fixed.
Nevertheless, I am afraid that on the whole, I got into very confused state about how to use omego and mainly how to construct the commands.
~/Work/omego/omego/main.py install --upgradedb --dbname old_db to my surprise just started to do something, although I thought it will end up immediately with an error.
@manics : Would you please be able to advise a workflow about how to reasonably execute the command from the header or is it okay to conclude here that #69 (comment) is fixed ?

@manics
Copy link
Member Author

manics commented Jan 24, 2016

@pwalczysko The flag was changed (#74 (comment)) so that the omero config file will be used during upgrades unless --no-db-config is given.

omego upgrade -v --sym OMERO-TEST --upgradedb should upgrade your db and server providing OMERO-TEST points to your existing server.

omego install -v --sym OMERO-TEST --upgradedb --dbname old_db will install a new server, but use an existing OMERO database called old_db and will upgrade it if necessary. In this case since you don't have an existing server or config file you'll need to explicitly provide --dbuser, --dbpass, and --dbhost if they are different from the defaults.

@pwalczysko
Copy link
Member

step 1: I have created an old_db (a 5.0 DB) from scratch which I have connected successfully to an 5.0.0 server. Now I suppose that this old_db has the required config file (as per header of this PR).
In next step, I will

  • create the OMERO-TEST directory and link it to a new 5.2 server
  • execute the omego upgrade -v --sym OMERO-TEST --upgradedb --use-db-config
  • expect that the old_db will be upgraded to the level of this new server

@manics
Copy link
Member Author

manics commented Jan 26, 2016

OMERO-TEST should point to your old server before you start (since you are doing an upgrade). omego upgrade will switch the symlink to point to the new server as part of the upgrade process.

@pwalczysko
Copy link
Member

.[pwalczysko@ls31619 ~/Work/omego]$ ./omego/main.py db dump --serverdir OMERO-TEST --dumpfile dump_of_old_db
2016-01-27 10:28:39,177 [        root] INFO  Processing custom settings for module omeroweb.settings
2016-01-27 10:28:39,295 [    omego.db] INFO  DbAdmin: DbAdmin OMERO-TEST ...
Traceback (most recent call last):
  File "./omego/main.py", line 64, in <module>
    entry_point()
  File "./omego/main.py", line 54, in entry_point
    (Version.NAME, Version)])
  File "/usr/local/lib/python2.7/site-packages/yaclifw/framework.py", line 197, in main
    ns.func(ns)
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 283, in __call__
    DbAdmin(d, args.dbcommand, args, ext)
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 35, in __init__
    psqlv = self.psql('--version')
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 210, in psql
    db, env = self.get_db_args_env()
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 190, in get_db_args_env
    c = self.external.get_config()
  File "/Users/pwalczysko/Work/omego/omego/external.py", line 85, in get_config
    exclusive=False, read_only=True)
TypeError: __init__() got an unexpected keyword argument 'read_only'
[pwalczysko@ls31619 ~/Work/omego]$ 

Trying to make the dump of the DB which is 5.0 connected to the 5.0 server.

@pwalczysko
Copy link
Member

The command
./omego/main.py upgrade -v --sym OMERO-TEST --upgradedb failed with

2016-01-27 10:47:40,077 [    omego.db] INFO  DbAdmin: DbAdmin ./OMERO.server-5.2.1-ice35-b15 ...
Traceback (most recent call last):
  File "./omego/main.py", line 64, in <module>
    entry_point()
  File "./omego/main.py", line 54, in entry_point
    (Version.NAME, Version)])
  File "/usr/local/lib/python2.7/site-packages/yaclifw/framework.py", line 197, in main
    ns.func(ns)
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 415, in __call__
    UnixInstall(self.NAME, args)
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 70, in __init__
    self.upgrade_db()
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 205, in upgrade_db
    DbAdmin(self.dir, 'upgrade', self.args, self.external)
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 35, in __init__
    psqlv = self.psql('--version')
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 210, in psql
    db, env = self.get_db_args_env()
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 200, in get_db_args_env
    raise Exception('Database name required')
Exception: Database name required
2016-01-27 10:47:40,080 [omero.util.T] DEBUG Removing tree: /Users/pwalczysko/omero/tmp/omero_pwalczysko/55577
[pwalczysko@ls31619 ~/Work/omego]$ ./omego/main.py upgrade -v --sym OMERO-TEST --upgradedb

Again, 5.0 db and 5.0 server.

Older versions of OMERO don't support this flag
@manics
Copy link
Member Author

manics commented Feb 2, 2016

omego db dump --serverdir OMERO.server-5.0.0-ice35-b19 -v should work with the last commit

@pwalczysko
Copy link
Member

./omego/main.py db dump --serverdir OMERO-TEST --dumpfile dump_of_old_db executed without error and created a file dump_of_old_db as expected.

@pwalczysko
Copy link
Member

Nevertheless the command
./omego/main.py upgrade -v --sym OMERO-TEST --upgradedb
failed with

2016-02-04 15:44:01,930 [omego.upgrad] DEBUG Upgrading database
2016-02-04 15:44:01,931 [    omego.db] INFO  DbAdmin: DbAdmin ./OMERO.server-5.2.1-ice35-b15 ...
Traceback (most recent call last):
  File "./omego/main.py", line 64, in <module>
    entry_point()
  File "./omego/main.py", line 54, in entry_point
    (Version.NAME, Version)])
  File "/usr/local/lib/python2.7/site-packages/yaclifw/framework.py", line 197, in main
    ns.func(ns)
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 415, in __call__
    UnixInstall(self.NAME, args)
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 70, in __init__
    self.upgrade_db()
  File "/Users/pwalczysko/Work/omego/omego/upgrade.py", line 205, in upgrade_db
    DbAdmin(self.dir, 'upgrade', self.args, self.external)
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 35, in __init__
    psqlv = self.psql('--version')
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 210, in psql
    db, env = self.get_db_args_env()
  File "/Users/pwalczysko/Work/omego/omego/db.py", line 200, in get_db_args_env
    raise Exception('Database name required')
Exception: Database name required
2016-02-04 15:44:01,932 [omero.util.T] DEBUG Removing tree: /Users/pwalczysko/omero/tmp/omero_pwalczysko/31344
[pwalczysko@ls31619 ~/Work/omego]$ 

Again, the attempted upgrade was from 5.0.0 server (downloads page).

THe presence/absence of config.xml is recorded at initialisation since importing omero.cli may lead to the creation of an empty config.xml when previosuly there was none. However for a server upgrade we want to re-read the config.xml after it is copied.
@manics
Copy link
Member Author

manics commented Feb 5, 2016

@pwalczysko Sorry about that, I thought it was tested by travis but it wasn't (though it is now). Should all be working now.

@pwalczysko
Copy link
Member

./omego/main.py upgrade -v --sym OMERO-TEST --upgradedb works fine now.
The DB was verified as upgraded from 5.0 to 5.2

old_db=# select * from dbpatch;
 id | currentpatch | currentversion | permissions |          finished          |                                           message                                            | previouspatch | previousversion | external_id 
----+--------------+----------------+-------------+----------------------------+----------------------------------------------------------------------------------------------+---------------+-----------------+-------------
  1 |            0 | OMERO5.0       |         -52 | 2016-01-21 15:32:20.333478 | Database ready.                                                                              |             0 | OMERO5.0        |            
  2 |            1 | OMERO5.1       |         -52 | 2016-02-08 15:16:40.356604 | Database updated.                                                                            |             0 | OMERO5.0        |            
  3 |            0 | OMERO5.2       |         -52 | 2016-02-08 15:16:40.395968 | Database updated.                                                                            |             1 | OMERO5.1        |            
  4 |            0 | OMERO5.2       |         -52 | 2016-02-08 15:16:51.084905 | DB check DBEnumCheck: done for Bio-Formats revision 8ef015dc4b2a5f2035e49486c9da9a9f301b53cc |             0 | OMERO5.2        |            
  5 |            0 | OMERO5.2       |         -52 | 2016-02-08 15:16:51.098742 | DB check DBUnicodeUnitsCheck: done                                                           |             0 | OMERO5.2        |            
(5 rows)

The server has started successfully.
Ready to merge.

joshmoore added a commit that referenced this pull request Feb 9, 2016
Parse config.xml for db parameters, add omero db dump
@joshmoore joshmoore merged commit 41693e1 into ome:master Feb 9, 2016
@manics manics deleted the pgdump branch February 9, 2016 10:39
@joshmoore joshmoore added this to the 0.3.0 milestone Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants