Project

General

Profile

1
Installation:
2
	Check out svn: svn co https://code.nceas.ucsb.edu/code/projects/bien
3
	cd bien/
4
	Install: make install
5
		WARNING: This will delete the current public schema of your VegBIEN DB!
6
	Uninstall: make uninstall
7
		WARNING: This will delete your entire VegBIEN DB!
8
		This includes all archived imports and staging tables.
9

    
10
Maintenance:
11
	to synchronize vegbiendev, jupiter, and your local machine:
12
		install put if needed:
13
			download https://uutils.googlecode.com/svn/trunk/bin/put to ~/bin/ and `chmod +x` it
14
		when changes are made on vegbiendev:
15
			on vegbiendev, upload:
16
				env overwrite=1             src=. dest='aaronmk@jupiter:~/bien' put --no-group --exclude=.svn --exclude=install.log.sql --exclude='*.backup' --exclude='/backups/analytical_aggregate.*.csv' --exclude='inputs/GBIF/**.data.sql' --exclude='bin/dotlockfile'
17
					then rerun with env l=1 ...
18
				env overwrite=1 del=        src=. dest='aaronmk@jupiter:~/bien' put --no-group --exclude=.svn --exclude=install.log.sql --exclude='inputs/GBIF/**.data.sql'
19
					then rerun with env l=1 ...
20
			on your machine, download:
21
				env overwrite=1      swap=1 src=. dest='aaronmk@jupiter:~/bien' put            --exclude=.svn inputs/VegBIEN/TWiki
22
					then rerun with env l=1 ...
23
				env overwrite=1 del= swap=1 src=. dest='aaronmk@jupiter:~/bien' put            --exclude=.svn --exclude=install.log.sql --exclude='*.backup' --exclude='/backups/analytical_aggregate.*.csv' --exclude='inputs/GBIF/**.data.sql' --exclude='bin/dotlockfile'
24
					then rerun with env l=1 ...
25
	to synchronize a Mac's settings with my testing machine's:
26
		download:
27
			WARNING: this will overwrite all your user's settings!
28
			env overwrite=1 swap=1 src=~/Library/ dest='aaronmk@jupiter:~/Library/' put --exclude="/Saved Application State"
29
				then rerun with env l=1 ...
30
		upload:
31
			do step when changes are made on vegbiendev > on your machine, download
32
			env overwrite=1        src=~ dest='aaronmk@jupiter:~' put --exclude="/Library/Saved Application State" --exclude="/.Trash" --exclude="/bin" --exclude="/bin/pg_ctl" --exclude="/bin/unzip" --exclude="/Documents/BIEN/large_files" --exclude="/Documents/BIEN/svn/backups/*.backup" --exclude="/Documents/BIEN/svn/backups/analytical_aggregate.*.csv" --exclude="/Dropbox/home"
33
				then rerun with env l=1 ...
34
			env overwrite=1        src=~ dest=~/Dropbox/home      put --exclude="/Library/Saved Application State" --exclude="/.Trash" --exclude="/.dropbox" --exclude="/Documents/BIEN" --exclude="/Dropbox" --exclude="/software" --exclude="/VirtualBox VMs/**.sav" --exclude="/VirtualBox VMs/**.vdi" --exclude="/VirtualBox VMs/**.vmdk"
35
				then rerun with env l=1 ...
36
	to backup files not in Time Machine:
37
		env inplace=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ put Users/aaronmk/VirtualBox\ VMs/
38
			then rerun with env l=1 ...
39
		stop the PostgreSQL server
40
		sudo env src=/ dest=/Volumes/Time\ Machine\ Backups/ put Library/PostgreSQL/9.1/data/
41
			then rerun with env l=1 ...
42
		start the PostgreSQL server
43
	VegCore data dictionary:
44
		Regularly, or whenever the VegCore data dictionary page
45
			(https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore)
46
			is changed, regenerate mappings/VegCore.csv:
47
			make mappings/VegCore.htm-remake; make mappings/
48
			svn di mappings/VegCore.tables.redmine
49
			If there are changes, update the data dictionary's Tables section
50
			When moving terms, check that no terms were lost: svn di
51
			svn ci -m "mappings/VegCore.htm: Regenerated from wiki"
52
	Important: Whenever you install a system update that affects PostgreSQL or
53
		any of its dependencies, such as libc, you should restart the PostgreSQL
54
		server. Otherwise, you may get strange errors like "the database system
55
		is in recovery mode" which go away upon reimport, or you may not be able
56
		to access the database as the postgres superuser. This applies to both
57
		Linux and Mac OS X.
58

    
59
Single datasource import:
60
	(Re)import and scrub: make inputs/<datasrc>/reimport_scrub by_col=1
61
	(Re)import only: make inputs/<datasrc>/reimport by_col=1
62
	(Re)scrub: make inputs/<datasrc>/rescrub by_col=1
63
	Note that these commands also work if the datasource is not yet imported
64

    
65
Full database import:
66
	On jupiter: svn up
67
	On local machine:
68
		./fix_perms
69
		make inputs/upload
70
		make test by_col=1
71
			See note under Testing below
72
	On vegbiendev:
73
	Ensure there are no local modifications: svn st
74
	svn up
75
	make inputs/download
76
	For each newly-uploaded datasource above: make inputs/<datasrc>/reinstall
77
	Update the auxiliary schemas: make schemas/reinstall
78
		The public schema will be installed separately by the import process
79
	Delete imports before the last so they won't bloat the full DB backup:
80
		make backups/vegbien.<version>.backup/remove
81
		To keep a previous import other than the public schema:
82
			export dump_opts='--exclude-schema=public --exclude-schema=<version>'
83
	Make sure there is at least 150GB of disk space on /: df -h
84
		The import schema is 100GB, and may use additional space for temp tables
85
		To free up space, remove backups that have been archived on jupiter:
86
			List backups/ to view older backups
87
			Check their MD5 sums using the steps under On jupiter below
88
			Remove these backups
89
	unset version
90
	screen
91
	Press ENTER
92
	Start column-based import: . bin/import_all by_col=1
93
		To use row-based import: . bin/import_all
94
		To stop all running imports: . bin/stop_imports
95
		WARNING: Do NOT run import_all in the background, or the jobs it creates
96
			won't be owned by your shell.
97
		Note that import_all will take up to an hour to import the NCBI backbone
98
			and other metadata before returning control to the shell.
99
	Wait (overnight) for the import to finish
100
	To recover from a closed terminal window: screen -r
101
	When there are no more running jobs, exit the screen
102
	Get $version: echo $version
103
	Set $version in all vegbiendev terminals: export version=<version>
104
	Upload logs (run on vegbiendev): make inputs/upload
105
	On local machine: make inputs/download-logs
106
	In PostgreSQL:
107
		Check that the provider_count and source tables contain entries for all
108
			inputs
109
	tail inputs/{.,}*/*/logs/$version.log.sql
110
	In the output, search for "Command exited with non-zero status"
111
	For inputs that have this, fix the associated bug(s)
112
	If many inputs have errors, discard the current (partial) import:
113
		make schemas/$version/uninstall
114
	Otherwise, continue
115
	make schemas/$version/publish
116
	unset version
117
	backups/fix_perms
118
	make backups/upload
119
	On jupiter:
120
		cd /data/dev/aaronmk/bien/backups
121
		For each newly-archived backup:
122
			make -s <backup>.md5/test
123
			Check that "OK" is printed next to the filename
124
	On nimoy:
125
		cd /home/bien/svn/
126
		svn up
127
		export version=<version>
128
		make backups/analytical_stem.$version.csv/download
129
		In the bien_web DB:
130
			Create the analytical_stem_<version> table using its schema
131
				in schemas/vegbien.my.sql
132
		make -s backups/analytical_stem.$version.csv.md5/test
133
		Check that "OK" is printed next to the filename
134
		env table=analytical_stem_$version bin/publish_analytical_db \
135
			backups/analytical_stem.$version.csv
136
	If desired, record the import times in inputs/import.stats.xls:
137
		Open inputs/import.stats.xls
138
		If the rightmost import is within 5 columns of column IV:
139
			Copy the current tab to <leftmost-date>~<rightmost-date>
140
			Remove the previous imports from the current tab because they are
141
				now in the copied tab instead
142
		Insert a copy of the leftmost "By column" column group before it
143
		export version=<version>
144
		bin/import_date inputs/{.,}*/*/logs/$version.log.sql
145
		Update the import date in the upper-right corner
146
		bin/import_times inputs/{.,}*/*/logs/$version.log.sql
147
		Paste the output over the # Rows/Time columns, making sure that the
148
			row counts match up with the previous import's row counts
149
		If the row counts do not match up, insert or reorder rows as needed
150
			until they do. Get the datasource names from the log file footers:
151
			tail inputs/{.,}*/*/logs/$version.log.sql
152
		Commit: svn ci -m "inputs/import.stats.xls: Updated import times"
153
	To run TNRS: make scrub by_col=1 &
154
		export version=<version>
155
		To view progress:
156
			tail -100 inputs/.TNRS/tnrs/logs/tnrs.make.log.sql
157
	To remake analytical DB: bin/make_analytical_db &
158
		export version=<version>
159
		To view progress:
160
			tail -100 inputs/analytical_db/logs/make_analytical_db.log.sql
161
	To back up DB (staging tables and last import):
162
		export version=<version>
163
		If before renaming to public: export dump_opts=--exclude-schema=public
164
		make backups/vegbien.$version.backup/test &
165

    
166
Backups:
167
	Archived imports:
168
		Back up: make backups/<version>.backup &
169
			Note: To back up the last import, you must archive it first:
170
				make schemas/rotate
171
		Test: make -s backups/<version>.backup/test &
172
		Restore: make backups/<version>.backup/restore &
173
		Remove: make backups/<version>.backup/remove
174
		Download: make backups/download
175
	TNRS cache:
176
		Back up: make backups/TNRS.backup-remake &
177
		Restore:
178
			yes|make inputs/.TNRS/uninstall
179
			make backups/TNRS.backup/restore &
180
			yes|make schemas/public/reinstall
181
				Must come after TNRS restore to recreate tnrs_input_name view
182
	Full DB:
183
		Back up: make backups/vegbien.<version>.backup &
184
		Test: make -s backups/vegbien.<version>.backup/test &
185
		Restore: make backups/vegbien.<version>.backup/restore &
186
		Download: make backups/download
187
	Import logs:
188
		Download: make inputs/download-logs
189

    
190
Datasource setup:
191
	umask ug=rwx,o= # prevent files from becoming web-accessible
192
	Add a new datasource: make inputs/<datasrc>/add
193
		<datasrc> may not contain spaces, and should be abbreviated.
194
		If the datasource is a herbarium, <datasrc> should be the herbarium code
195
			as defined by the Index Herbariorum <http://sweetgum.nybg.org/ih/>
196
	For MySQL inputs (exports and live DB connections):
197
		For .sql exports:
198
			Place the original .sql file in _src/ (*not* in _MySQL/)
199
			Follow the steps starting with Install the staging tables below.
200
				This is for an initial sync to get the file onto vegbiendev.
201
			On vegbiendev:
202
				Create a database for the MySQL export in phpMyAdmin
203
				bin/mysql_bien database <inputs/<datasrc>/_src/export.sql &
204
		mkdir inputs/<datasrc>/_MySQL/
205
		cp -p lib/MySQL.{data,schema}.sql.make inputs/<datasrc>/_MySQL/
206
		Edit _MySQL/*.make for the DB connection
207
			For a .sql export, use server=vegbiendev and --user=bien
208
		Skip the Add input data for each table section
209
	For MS Access databases:
210
		Place the .mdb or .accdb file in _src/
211
		Download and install Access To PostgreSQL from
212
			http://www.bullzip.com/download.php
213
		Use Access To PostgreSQL to export the database:
214
			Export just the tables/indexes to inputs/<datasrc>/<file>.schema.sql
215
			Export just the data to inputs/<datasrc>/<file>.data.sql
216
		In <file>.schema.sql, make the following changes:
217
			Replace text "BOOLEAN" with "/*BOOLEAN*/INTEGER"
218
			Replace text "DOUBLE PRECISION NULL" with "DOUBLE PRECISION"
219
		Skip the Add input data for each table section
220
	Add input data for each table present in the datasource:
221
		For .sql exports, you must use the name of the table in the DB export
222
		For CSV files, you can use any name. It's recommended to use a table
223
			name from <https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCSV#Suggested-table-names>
224
		Note that if this table will be joined together with another table, its
225
			name must end in ".src"
226
		make inputs/<datasrc>/<table>/add
227
			Important: DO NOT just create an empty directory named <table>!
228
				This command also creates necessary subdirs, such as logs/.
229
		If the table is in a .sql export: make inputs/<datasrc>/<table>/install
230
			Otherwise, place the CSV(s) for the table in
231
			inputs/<datasrc>/<table>/ OR place a query joining other tables
232
			together in inputs/<datasrc>/<table>/create.sql
233
		Important: When exporting relational databases to CSVs, you MUST ensure
234
			that embedded quotes are escaped by doubling them, *not* by
235
			preceding them with a "\" as is the default in phpMyAdmin
236
		If there are multiple part files for a table, and the header is repeated
237
			in each part, make sure each header is EXACTLY the same.
238
			(If the headers are not the same, the CSV concatenation script
239
			assumes the part files don't have individual headers and treats the
240
			subsequent headers as data rows.)
241
		Add <table> to inputs/<datasrc>/import_order.txt before other tables
242
			that depend on it
243
	Install the staging tables:
244
		make inputs/<datasrc>/reinstall quiet=1 &
245
		For a MySQL .sql export:
246
			At prompt "[you]@vegbiendev's password:", enter your password
247
			At prompt "Enter password:", enter the value in config/bien_password
248
		To view progress: tail -f inputs/<datasrc>/<table>/logs/install.log.sql
249
		View the logs: tail -n +1 inputs/<datasrc>/*/logs/install.log.sql
250
			tail provides a header line with the filename
251
			+1 starts at the first line, to show the whole file
252
		For every file with an error 'column "..." specified more than once':
253
			Add a header override file "+header.<ext>" in <table>/:
254
				Note: The leading "+" should sort it before the flat files.
255
					"_" unfortunately sorts *after* capital letters in ASCII.
256
				Create a text file containing the header line of the flat files
257
				Add an ! at the beginning of the line
258
					This signals cat_csv that this is a header override.
259
				For empty names, use their 0-based column # (by convention)
260
				For duplicate names, add a distinguishing suffix
261
				For long names that collided, rename them to <= 63 chars long
262
				Do NOT make readability changes in this step; that is what the
263
					map spreadsheets (below) are for.
264
				Save
265
		If you made any changes, re-run the install command above
266
	Auto-create the map spreadsheets: make inputs/<datasrc>/
267
	Map each table's columns:
268
		In each <table>/ subdir, for each "via map" map.csv:
269
			Open the map in a spreadsheet editor
270
			Open the "core map" /mappings/Veg+-VegBIEN.csv
271
			In each row of the via map, set the right column to a value from the
272
				left column of the core map
273
			Save
274
		Regenerate the derived maps: make inputs/<datasrc>/
275
	Accept the test cases:
276
		make inputs/<datasrc>/test
277
			When prompted to "Accept new test output", enter y and press ENTER
278
			If you instead get errors, do one of the following for each one:
279
			-	If the error was due to a bug, fix it
280
			-	Add a SQL function that filters or transforms the invalid data
281
			-	Make an empty mapping for the columns that produced the error.
282
				Put something in the Comments column of the map spreadsheet to
283
				prevent the automatic mapper from auto-removing the mapping.
284
			When accepting tests, it's helpful to use WinMerge
285
				(see WinMerge setup below for configuration)
286
		make inputs/<datasrc>/test by_col=1
287
			If you get errors this time, this always indicates a bug, usually in
288
				the VegBIEN unique constraints or column-based import itself
289
	Add newly-created files: make inputs/<datasrc>/add
290
	Commit: svn ci -m "Added inputs/<datasrc>/" inputs/<datasrc>/
291
	Update vegbiendev:
292
		On jupiter: svn up
293
		On local machine:
294
			./fix_perms
295
			make inputs/upload
296
		On vegbiendev:
297
			svn up
298
			make inputs/download
299
			Follow the steps under Install the staging tables above
300

    
301
Datasource refreshing:
302
	VegBank:
303
		make inputs/VegBank/vegbank.sql-remake
304
		make inputs/VegBank/reinstall quiet=1 &
305

    
306
Schema changes:
307
	When changing the analytical views, run sync_analytical_..._to_view()
308
		to update the corresponding table
309
	Remember to update the following files with any renamings:
310
		schemas/filter_ERD.csv
311
		mappings/VegCore-VegBIEN.csv
312
		mappings/verify.*.sql
313
	Regenerate schema from installed DB: make schemas/remake
314
	Reinstall DB from schema: make schemas/public/reinstall schemas/reinstall
315
		WARNING: This will delete the current public schema of your VegBIEN DB!
316
	Reinstall staging tables:
317
		On local machine:
318
			sudo -E -u postgres psql <<<'ALTER DATABASE vegbien RENAME TO vegbien_prev'
319
			make db
320
			. bin/reinstall_all
321
			Fix any bugs and retry until no errors
322
			make schemas/public/install
323
				This must be run *after* the datasources are installed, because
324
				views in public depend on some of the datasources
325
			sudo -E -u postgres psql <<<'DROP DATABASE vegbien_prev'
326
		On vegbiendev: repeat the above steps
327
			WARNING: Do not run this until reinstall_all runs successfully on
328
			the local machine, or the live DB may be unrestorable!
329
	Sync ERD with vegbien.sql schema:
330
		Run make schemas/vegbien.my.sql
331
		Open schemas/vegbien.ERD.mwb in MySQLWorkbench
332
		Go to File > Export > Synchronize With SQL CREATE Script...
333
		For Input File, select schemas/vegbien.my.sql
334
		Click Continue
335
		In the changes list, select each table with an arrow next to it
336
		Click Update Model
337
		Click Continue
338
		Note: The generated SQL script will be empty because we are syncing in
339
			the opposite direction
340
		Click Execute
341
		Reposition any lines that have been reset
342
		Add any new tables by dragging them from the Catalog in the left sidebar
343
			to the diagram
344
		Remove any deleted tables by right-clicking the table's diagram element,
345
			selecting Delete '<table name>', and clicking Delete
346
		Save
347
		If desired, update the graphical ERD exports (see below)
348
	Update graphical ERD exports:
349
		Go to File > Export > Export as PNG...
350
		Select schemas/vegbien.ERD.png and click Save
351
		Go to File > Export > Export as SVG...
352
		Select schemas/vegbien.ERD.svg and click Save
353
		Go to File > Export > Export as Single Page PDF...
354
		Select schemas/vegbien.ERD.1_pg.pdf and click Save
355
		Go to File > Print...
356
		In the lower left corner, click PDF > Save as PDF...
357
		Set the Title and Author to ""
358
		Select schemas/vegbien.ERD.pdf and click Save
359
		Commit: svn ci -m "schemas/vegbien.ERD.mwb: Regenerated exports"
360
	Refactoring tips:
361
		To rename a table:
362
			In vegbien.sql, do the following:
363
				Replace regexp (?<=_|\b)<old>(?=_|\b) with <new>
364
					This is necessary because the table name is *everywhere*
365
				Search for <new>
366
				Manually change back any replacements inside comments
367
		To rename a column:
368
			Rename the column: ALTER TABLE <table> RENAME <old> TO <new>;
369
			Recreate any foreign key for the column, removing CONSTRAINT <name>
370
				This resets the foreign key name using the new column name
371
	Creating a poster of the ERD:
372
		Determine the poster size:
373
			Measure the line height (from the bottom of one line to the bottom
374
				of another): 16.3cm/24 lines = 0.679cm
375
			Measure the height of the ERD: 35.4cm*2 = 70.8cm
376
			Zoom in as far as possible
377
			Measure the height of a capital letter: 3.5mm
378
			Measure the line height: 8.5mm
379
			Calculate the text's fraction of the line height: 3.5mm/8.5mm = 0.41
380
			Calculate the text height: 0.679cm*0.41 = 0.28cm
381
			Calculate the text height's fraction of the ERD height:
382
				0.28cm/70.8cm = 0.0040
383
			Measure the text height on the *VegBank* ERD poster: 5.5mm = 0.55cm
384
			Calculate the VegBIEN poster height to make the text the same size:
385
				0.55cm/0.0040 = 137.5cm H; *1in/2.54cm = 54.1in H
386
			The ERD aspect ratio is 11 in W x (2*8.5in H) = 11x17 portrait
387
			Calculate the VegBIEN poster width: 54.1in H*11W/17H = 35.0in W
388
			The minimum VegBIEN poster size is 35x54in portrait
389
		Determine the cost:
390
			The FedEx Kinkos near NCEAS (1030 State St, Santa Barbara, CA 93101)
391
				charges the following for posters:
392
				base: $7.25/sq ft
393
				lamination: $3/sq ft
394
				mounting on a board: $8/sq ft
395

    
396
Testing:
397
	On a development machine, you should put the following in your .profile:
398
		umask ug=rwx,o= # prevent files from becoming web-accessible
399
		export log= n=2
400
	Mapping process: make test
401
		Including column-based import: make test by_col=1
402
			If the row-based and column-based imports produce different inserted
403
			row counts, this usually means that a table is underconstrained
404
			(the unique indexes don't cover all possible rows).
405
			This can occur if you didn't use COALESCE(field, null_value) around
406
			a nullable field in a unique index. See sql_gen.null_sentinels for
407
			the appropriate null value to use.
408
	Map spreadsheet generation: make remake
409
	Missing mappings: make missing_mappings
410
	Everything (for most complete coverage): make test-all
411

    
412
Debugging:
413
	"Binary chop" debugging:
414
		(This is primarily useful for regressions that occurred in a previous
415
		revision, which was committed without running all the tests)
416
		svn up -r <rev>; make inputs/.TNRS/reinstall; make schemas/public/reinstall; make <failed-test>.xml
417
	.htaccess:
418
		mod_rewrite:
419
			IMPORTANT: whenever you change the DirectorySlash setting for a
420
				directory, you *must* clear your browser's cache to ensure that
421
				a cached redirect is not used. this is because RewriteRule
422
				redirects are (by default) temporary, but DirectorySlash
423
				redirects are permanent.
424
				for Firefox:
425
					press Cmd+Shift+Delete
426
					check only Cache
427
					press Enter or click Clear Now
428

    
429
WinMerge setup:
430
	Install WinMerge from <http://winmerge.org/>
431
	Open WinMerge
432
	Go to Edit > Options and click Compare in the left sidebar
433
	Enable "Moved block detection", as described at
434
		<http://manual.winmerge.org/Configuration.html#d0e5892>.
435
	Set Whitespace to Ignore change, as described at
436
		<http://manual.winmerge.org/Configuration.html#d0e5758>.
437

    
438
Documentation:
439
	To generate a Redmine-formatted list of steps for column-based import:
440
		make schemas/public/reinstall
441
		make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
442
	To import and scrub just the test taxonomic names:
443
		inputs/test_taxonomic_names/test_scrub
444

    
445
General:
446
	To see a program's description, read its top-of-file comment
447
	To see a program's usage, run it without arguments
448
	To remake a directory: make <dir>/remake
449
	To remake a file: make <file>-remake
(3-3/8)