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 --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 --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 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'
22
					then rerun with env l=1 ...
23
	to synchronize a Mac's settings with my testing machine's:
24
		download:
25
			WARNING: this will overwrite all your user's settings!
26
			env overwrite=1 swap=1 src=~/Library/ dest='aaronmk@jupiter:~/Library/' put --exclude="/Saved Application State"
27
				then rerun with env l=1 ...
28
		upload:
29
			do step when changes are made on vegbiendev > on your machine, download
30
			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" --exclude="/Dropbox/home"
31
				then rerun with env l=1 ...
32
			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"
33
				then rerun with env l=1 ...
34
	to backup files not in Time Machine:
35
		env inplace=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ put Users/aaronmk/VirtualBox\ VMs/
36
			then rerun with env l=1 ...
37
		stop the PostgreSQL server
38
		sudo env src=/ dest=/Volumes/Time\ Machine\ Backups/ put Library/PostgreSQL/9.1/data/
39
			then rerun with env l=1 ...
40
		start the PostgreSQL server
41
	to backup the Ubuntu VM:
42
		env src=/Users/aaronmk/VirtualBox\ VMs/Ubuntu dest=/Volumes/Macintosh\ HD\ backup/Ubuntu put --exclude=/Ubuntu.prev.vdi
43
			then rerun with env l=1 ...
44
	VegCore data dictionary:
45
		Regularly, or whenever the VegCore data dictionary page
46
			(https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore)
47
			is changed, regenerate mappings/VegCore.csv:
48
			make mappings/VegCore.htm-remake; make mappings/
49
			svn di mappings/VegCore.tables.redmine
50
			If there are changes, update the data dictionary's Tables section
51
			When moving terms, check that no terms were lost: svn di
52
			svn ci -m "mappings/VegCore.htm: Regenerated from wiki"
53
	Important: Whenever you install a system update that affects PostgreSQL or
54
		any of its dependencies, such as libc, you should restart the PostgreSQL
55
		server. Otherwise, you may get strange errors like "the database system
56
		is in recovery mode" which go away upon reimport, or you may not be able
57
		to access the database as the postgres superuser. This applies to both
58
		Linux and Mac OS X.
59

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

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

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

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

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

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

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

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

    
418
WinMerge setup:
419
	Install WinMerge from <http://winmerge.org/>
420
	Open WinMerge
421
	Go to Edit > Options and click Compare in the left sidebar
422
	Enable "Moved block detection", as described at
423
		<http://manual.winmerge.org/Configuration.html#d0e5892>.
424
	Set Whitespace to Ignore change, as described at
425
		<http://manual.winmerge.org/Configuration.html#d0e5758>.
426

    
427
Documentation:
428
	To generate a Redmine-formatted list of steps for column-based import:
429
		make schemas/public/reinstall
430
		make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
431
	To import and scrub just the test taxonomic names:
432
		inputs/test_taxonomic_names/test_scrub
433

    
434
General:
435
	To see a program's description, read its top-of-file comment
436
	To see a program's usage, run it without arguments
437
	To remake a directory: make <dir>/remake
438
	To remake a file: make <file>-remake
(2-2/6)