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 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
Connecting to vegbiendev:
11
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
12
	cd /home/bien/svn # should happen automatically at login
13

    
14
Notes on running programs:
15
	**WARNING**: always start with a clean shell, to avoid spurious bugs. the
16
		shell should not have changes to the env vars. (there have been bugs
17
		that went away after closing and reopening the terminal window.) note
18
		that running `exec bash` is not sufficient to *reset* the env vars.
19

    
20
Notes on editing files:
21
	**WARNING**: shell scripts should always be read-only, so that editing them
22
		while an import is in progress will not crash the import (see
23
		http://vegpath.org/links/#**%20modifying%20a%20running%20shell%20script)
24

    
25
Single datasource import:
26
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
27
	(Re)import and scrub: make inputs/<datasrc>/reimport_scrub by_col=1 &
28
	(Re)import only: make inputs/<datasrc>/reimport by_col=1 &
29
	Note that these commands also work if the datasource is not yet imported
30
	Remake analytical DB: see Full database import > To remake analytical DB
31

    
32
Full database import:
33
	**WARNING**: You must perform *every single* step listed below, to avoid
34
		breaking column-based import
35
	**WARNING**: always start with a clean shell, as described above under
36
		"Notes on running programs"
37
	**IMPORTANT**: the beginning of the import should be scheduled at a time
38
		when the DB will not be needed for other uses. this is necessary because
39
		vegbiendev will be slow for the first few hours of the import, due to
40
		the import using all the available cores.
41
	do steps under Maintenance > "to synchronize vegbiendev, jupiter, and
42
		your local machine"
43
	On local machine:
44
		make inputs/upload
45
		make inputs/upload live=1
46
		make test by_col=1 # runtime: 20 min ("4m46.108s" + ("21:50:43" - "21:37:09")) @starscream
47
			if you encounter errors, they are most likely related to the
48
				PostgreSQL error parsing in /lib/sql.py parse_exception()
49
			See note under Testing below
50
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
51
	Ensure there are no local modifications: svn st
52
	up
53
	make inputs/download
54
	make inputs/download live=1
55
	For each newly-uploaded datasource above: make inputs/<datasrc>/reinstall
56
	Update the auxiliary schemas: make schemas/reinstall
57
		**WARNING**: requires sudo access!
58
		The public schema will be installed separately by the import process
59
	Delete imports before the last so they won't bloat the full DB backup:
60
		make backups/vegbien.<version>.backup/remove
61
		To keep a previous import other than the public schema:
62
			export dump_opts='--exclude-schema=public --exclude-schema=<version>'
63
			# env var will be inherited by `screen` shell
64
	restart Postgres to free up any disk space used by temp tables from the last
65
		import (this is apparently not automatically reclaimed):
66
		make postgres_restart
67
	Make sure there is at least 1 TB of disk space on /: df -h
68
		**WARNING**: sometimes, this amount of available space is insufficient
69
			and the entire disk space gets used up, crashing the import. if this
70
			occurs, the problem will often be fixed just by rerunning the import
71
			again. (the high-water mark varies by import.)
72
		although the import schema itself is only 315 GB, Postgres uses
73
			significant temporary space at the beginning of the import. the
74
			total disk usage reaches 1.7+ TB in the first hour
75
			("14:00:25"-"12:55:09"), and then oscillates between 1.2-1.6 TB in
76
			the following 2+ hours.
77
		To free up space, remove backups that have been archived on jupiter:
78
			List backups/ to view older backups
79
			Check their MD5 sums using the steps under On jupiter below
80
			Remove these backups
81
	unset version # clear any version from last import, etc.
82
	if no commits have been made since the last import (eg. if retrying an
83
		import), set a custom version that differs from the auto-assigned one
84
		(would otherwise cause a collision with the last import):
85
		svn info
86
		extract the svn revision after "Revision:"
87
		export version=r[revision]_2 # +suffix to distinguish from last import
88
			# env var will be inherited by `screen` shell
89
	screen
90
	Press ENTER
91
	unset TMOUT # TMOUT causes screen to exit even with background processes
92
	set -o ignoreeof #prevent Ctrl+D from exiting `screen` to keep attached jobs
93
	Start column-based import: . bin/import_all
94
		To use row-based import: . bin/import_all by_col=
95
		To stop all running imports: . bin/stop_imports
96
		**WARNING**: Do NOT run import_all in the background, or the jobs it
97
			creates 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
		To view progress:
101
			tail inputs/{.,}*/*/logs/$version.log.sql
102
	note: at the beginning of the import, the system may send out CPU load
103
		warning e-mails. these can safely be ignored. (they happen because the
104
		parallel imports use all the available cores.)
105
	Wait (4 days) for the import to finish
106
	To recover from a closed terminal window: screen -r
107
	To restart an aborted import for a specific table:
108
		export version=<version>
109
		(set -o errexit; make inputs/<datasrc>/<table>/import_scrub by_col=1 continue=1; make inputs/<datasrc>/publish) &
110
		bin/after_import $! & # $! can also be obtained from `jobs -l`
111
	Get $version: echo $version
112
	Set $version in all vegbiendev terminals: export version=<version>
113
	When there are no more running jobs, exit `screen`: exit # not Ctrl+D
114
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
115
		Upload logs: make inputs/upload live=1
116
	On local machine: make inputs/download-logs live=1
117
	In PostgreSQL:
118
		Go to wiki.vegpath.org/VegBIEN_contents
119
		Get the # observations
120
		Get the # datasources
121
		Get the # datasources with observations
122
		in the r# schema:
123
		Check that analytical_stem contains [# observations] rows
124
		Check that source contains [# datasources] rows up through XAL. If this
125
			is not the case, manually check the entries in source against the
126
			datasources list on the wiki page (some datasources may be near the
127
			end depending on import order).
128
		Check that provider_count contains [# datasources with observations]
129
			rows with dataset="(total)" (at the top when the table is unsorted)
130
	Check that TNRS ran successfully:
131
		tail -100 inputs/.TNRS/tnrs/logs/tnrs.make.log.sql
132
		If the log ends in an AssertionError
133
			"assert sql.table_col_names(db, table) == header":
134
			Figure out which TNRS CSV columns have changed
135
			On local machine:
136
				Make the changes in the DB's TNRS and public schemas
137
				rm=1 inputs/.TNRS/schema.sql.run export_
138
				make schemas/remake
139
				inputs/test_taxonomic_names/test_scrub # re-run TNRS
140
				rm=1 inputs/.TNRS/data.sql.run export_
141
				Commit
142
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
143
				If dropping a column, save the dependent views
144
				Make the same changes in the live TNRS.tnrs table on vegbiendev
145
				If dropping a column, recreate the dependent views
146
				Restart the TNRS client: make scrub by_col=1 &
147
	tail inputs/{.,}*/*/logs/$version.log.sql
148
	In the output, search for "Command exited with non-zero status"
149
	For inputs that have this, fix the associated bug(s)
150
	If many inputs have errors, discard the current (partial) import:
151
		make schemas/$version/uninstall
152
	Otherwise, continue
153
	Publish the new import:
154
		**WARNING**: Before proceeding, be sure you have done *every single*
155
			verification step listed above. Otherwise, a previous valid import
156
			could incorrectly be overwritten with a broken one.
157
		make schemas/$version/publish # runtime: 1 min ("real 1m10.451s")
158
	unset version
159
	make backups/upload live=1
160
	on local machine:
161
		make backups/vegbien.$version.backup/download live=1
162
			# download backup to local machine
163
	ssh aaronmk@jupiter.nceas.ucsb.edu
164
		cd /data/dev/aaronmk/bien/backups
165
		For each newly-archived backup:
166
			make -s <backup>.md5/test
167
			Check that "OK" is printed next to the filename
168
	If desired, record the import times in inputs/import.stats.xls:
169
		On local machine:
170
		Open inputs/import.stats.xls
171
		If the rightmost import is within 5 columns of column IV:
172
			Copy the current tab to <leftmost-date>~<rightmost-date>
173
			Remove the previous imports from the current tab because they are
174
				now in the copied tab instead
175
		Insert a copy of the leftmost "By column" column group before it
176
		export version=<version>
177
		bin/import_date inputs/{.,}*/*/logs/$version.log.sql
178
		Update the import date in the upper-right corner
179
		bin/import_times inputs/{.,}*/*/logs/$version.log.sql
180
		Paste the output over the # Rows/Time columns, making sure that the
181
			row counts match up with the previous import's row counts
182
		If the row counts do not match up, insert or reorder rows as needed
183
			until they do. Get the datasource names from the log file footers:
184
			tail inputs/{.,}*/*/logs/$version.log.sql
185
		Commit: svn ci -m 'inputs/import.stats.xls: updated import times'
186
	Running individual steps separately:
187
	To run TNRS:
188
		To use an import other than public: export version=<version>
189
		make scrub &
190
		To view progress:
191
			tail -100 inputs/.TNRS/tnrs/logs/tnrs.make.log.sql
192
	To remake analytical DB:
193
		To use an import other than public: export version=<version>
194
		bin/make_analytical_db & # runtime: 13 h ("12:43:57elapsed")
195
		To view progress:
196
			tail -150 inputs/analytical_db/logs/make_analytical_db.log.sql
197
	To back up DB (staging tables and last import):
198
		To use an import *other than public*: export version=<version>
199
		make backups/TNRS.backup-remake &
200
		dump_opts=--exclude-schema=public make backups/vegbien.$version.backup/test &
201
			If after renaming to public, instead set dump_opts='' and replace
202
			$version with the appropriate revision
203
		make backups/upload live=1
204

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

    
334
Maintenance:
335
	on a live machine, you should put the following in your .profile:
336
--
337
# make svn files web-accessible. this does not affect unversioned files, because
338
# these get the right permissions on the local machine instead.
339
umask ug=rwx,o=rx
340

    
341
unset TMOUT # TMOUT causes screen to exit even with background processes
342
--
343
	if http://vegbiendev.nceas.ucsb.edu/phppgadmin/ goes down:
344
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
345
			make phppgadmin-Linux
346
	to synchronize vegbiendev, jupiter, and your local machine:
347
		**WARNING**: pay careful attention to all files that will be deleted or
348
			overwritten!
349
		install put if needed:
350
			download https://uutils.googlecode.com/svn/trunk/bin/put to ~/bin/ and `chmod +x` it
351
		when changes are made on vegbiendev:
352
			avoid extraneous diffs when rsyncing:
353
				on all machines:
354
				up
355
				./fix_perms
356
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
357
				upload:
358
				overwrite=1 bin/sync_upload --size-only
359
					then rerun with l=1 ...
360
			on your machine:
361
				download:
362
				overwrite=1 swap=1 src=. dest='aaronmk@jupiter.nceas.ucsb.edu:~/bien' put --exclude=.svn inputs/VegBIEN/TWiki
363
					then rerun with l=1 ...
364
				swap=1 bin/sync_upload backups/TNRS.backup
365
					then rerun with l=1 ...
366
				overwrite=1 swap=1 bin/sync_upload --size-only
367
					then rerun with l=1 ...
368
				overwrite=1 sync_remote_url=~/Dropbox/svn/ bin/sync_upload --existing --size-only # just update mtimes/perms
369
					then rerun with l=1 ...
370
	to back up e-mails:
371
		on local machine:
372
		/Applications/gmvault-v1.8.1-beta/bin/gmvault sync --multiple-db-owner --type quick aaronmk.nceas@gmail.com
373
		/Applications/gmvault-v1.8.1-beta/bin/gmvault sync --multiple-db-owner --type quick aaronmk@nceas.ucsb.edu
374
		open Thunderbird
375
		click the All Mail folder for each account and wait for it to download the e-mails in it
376
	to back up the version history:
377
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
378
		svnsync sync file:///home/aaronmk/Dropbox/docs/BIEN/svn_repo/ # initial runtime: 1.5 h ("08:21:38" - "06:45:26") @vegbiendev
379
		(cd ~/Dropbox/docs/BIEN/git/; git svn fetch)
380
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:~' put Dropbox/docs/BIEN/svn_repo/ # runtime: 1 min ("1:05.08")
381
			then rerun with l=1 ...
382
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:~' put Dropbox/docs/BIEN/git/
383
			then rerun with l=1 ...
384
		on local machine:
385
		overwrite=1 swap=1 src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:~' put Dropbox/docs/BIEN/svn_repo/ # runtime: 30 s ("36.19")
386
			then rerun with l=1 ...
387
		overwrite=1 swap=1 src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:~' put Dropbox/docs/BIEN/git/
388
			then rerun with l=1 ...
389
	to synchronize a Mac's settings with my testing machine's:
390
		download:
391
			**WARNING**: this will overwrite all your user's settings!
392
			on your machine:
393
			overwrite=1 swap=1 sync_local_dir=~/Library/ sync_remote_subdir=Library/ bin/sync_upload --exclude="/Saved Application State"
394
				then rerun with l=1 ...
395
		upload:
396
			do step when changes are made on vegbiendev > on your machine, download
397
			ssh aaronmk@jupiter.nceas.ucsb.edu
398
				(cd ~/Dropbox/svn/; up)
399
			on your machine:
400
				rm ~/'Library/Thunderbird/Profiles/9oo8rcyn.default/ImapMail/imap.googlemail.com/[Gmail].sbd/Spam'
401
					# remove the downloaded Spam folder, because spam e-mails often contain viruses that would trigger clamscan
402
				overwrite=1 del= sync_local_dir=~/Dropbox/svn/ sync_remote_subdir=Dropbox/svn/ bin/sync_upload --size-only # just update mtimes
403
					then rerun with l=1 ...
404
				overwrite=1      sync_local_dir=~              sync_remote_subdir=             bin/sync_upload --exclude="/Library/Saved Application State" --exclude="/.Trash" --exclude="/bin" --exclude="/bin/pg_ctl" --exclude="/bin/unzip" --exclude="/Dropbox/home" --exclude="/.profile" --exclude="/.shrc" --exclude="/.bashrc"
405
					then rerun with l=1 ...
406
				overwrite=1      sync_local_dir=~              sync_remote_url=~/Dropbox/home  bin/sync_upload --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"
407
					then rerun with l=1 ...
408
		upload just the VirtualBox VMs:
409
			on your machine:
410
				overwrite=1      sync_local_dir=~              sync_remote_subdir=             bin/sync_upload ~/"VirtualBox VMs/**"
411
					then rerun with l=1 ...
412
	to backup files not in Time Machine:
413
		On local machine:
414
		overwrite=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ sudo -E put Library/PostgreSQL/9.3/data/
415
			then rerun with l=1 ...
416
		pg_ctl. stop # stop the PostgreSQL server
417
		overwrite=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ sudo -E put Library/PostgreSQL/9.3/data/
418
			then rerun with l=1 ...
419
		pg_ctl. start # start the PostgreSQL server
420
	VegCore data dictionary:
421
		Regularly, or whenever the VegCore data dictionary page
422
			(https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore)
423
			is changed, regenerate mappings/VegCore.csv:
424
			On local machine:
425
			make mappings/VegCore.htm-remake; make mappings/
426
			apply new data dict mappings to datasource mappings/staging tables:
427
				inputs/run postprocess # runtime: see inputs/run
428
				time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
429
			svn di mappings/VegCore.tables.redmine
430
			If there are changes, update the data dictionary's Tables section
431
			When moving terms, check that no terms were lost: svn di
432
			svn ci -m 'mappings/VegCore.htm: regenerated from wiki'
433
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
434
				perform the steps under "apply new data dict mappings to
435
					datasource mappings/staging tables" above
436
	Important: Whenever you install a system update that affects PostgreSQL or
437
		any of its dependencies, such as libc, you should restart the PostgreSQL
438
		server. Otherwise, you may get strange errors like "the database system
439
		is in recovery mode" which go away upon reimport, or you may not be able
440
		to access the database as the postgres superuser. This applies to both
441
		Linux and Mac OS X.
442

    
443
Backups:
444
	Archived imports:
445
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
446
		Back up: make backups/<version>.backup &
447
			Note: To back up the last import, you must archive it first:
448
				make schemas/rotate
449
		Test: make -s backups/<version>.backup/test &
450
		Restore: make backups/<version>.backup/restore &
451
		Remove: make backups/<version>.backup/remove
452
		Download: make backups/<version>.backup/download
453
	TNRS cache:
454
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
455
		Back up: make backups/TNRS.backup-remake &
456
			runtime: 3 min ("real 2m48.859s")
457
		Restore:
458
			yes|make inputs/.TNRS/uninstall
459
			make backups/TNRS.backup/restore &
460
				runtime: 5.5 min ("real 5m35.829s")
461
			yes|make schemas/public/reinstall
462
				Must come after TNRS restore to recreate tnrs_input_name view
463
	Full DB:
464
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
465
		Back up: make backups/vegbien.<version>.backup &
466
		Test: make -s backups/vegbien.<version>.backup/test &
467
		Restore: make backups/vegbien.<version>.backup/restore &
468
		Download: make backups/vegbien.<version>.backup/download
469
	Import logs:
470
		On local machine:
471
		Download: make inputs/download-logs live=1
472

    
473
Datasource refreshing:
474
	VegBank:
475
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
476
		make inputs/VegBank/vegbank.sql-remake
477
		make inputs/VegBank/reinstall quiet=1 &
478

    
479
Schema changes:
480
	On local machine:
481
	When changing the analytical views, run sync_analytical_..._to_view()
482
		to update the corresponding table
483
	Remember to update the following files with any renamings:
484
		schemas/filter_ERD.csv
485
		mappings/VegCore-VegBIEN.csv
486
		mappings/verify.*.sql
487
	Regenerate schema from installed DB: make schemas/remake
488
	Reinstall DB from schema: make schemas/public/reinstall schemas/reinstall
489
		**WARNING**: This will delete the public schema of your VegBIEN DB!
490
	If needed, reinstall staging tables:
491
		On local machine:
492
			sudo -E -u postgres psql <<<'ALTER DATABASE vegbien RENAME TO vegbien_prev'
493
			make db
494
			. bin/reinstall_all
495
			Fix any bugs and retry until no errors
496
			make schemas/public/install
497
				This must be run *after* the datasources are installed, because
498
				views in public depend on some of the datasources
499
			sudo -E -u postgres psql <<<'DROP DATABASE vegbien_prev'
500
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
501
			repeat the above steps
502
			**WARNING**: Do not run this until reinstall_all runs successfully
503
			on the local machine, or the live DB may be unrestorable!
504
	update mappings and staging table column names:
505
		on local machine:
506
			inputs/run postprocess # runtime: see inputs/run
507
			time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
508
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
509
			manually apply schema changes to the live public schema
510
			do steps under "on local machine" above
511
	Sync ERD with vegbien.sql schema:
512
		Run make schemas/vegbien.my.sql
513
		Open schemas/vegbien.ERD.mwb in MySQLWorkbench
514
		Go to File > Export > Synchronize With SQL CREATE Script...
515
		For Input File, select schemas/vegbien.my.sql
516
		Click Continue
517
		In the changes list, select each table with an arrow next to it
518
		Click Update Model
519
		Click Continue
520
		Note: The generated SQL script will be empty because we are syncing in
521
			the opposite direction
522
		Click Execute
523
		Reposition any lines that have been reset
524
		Add any new tables by dragging them from the Catalog in the left sidebar
525
			to the diagram
526
		Remove any deleted tables by right-clicking the table's diagram element,
527
			selecting Delete '<table name>', and clicking Delete
528
		Save
529
		If desired, update the graphical ERD exports (see below)
530
	Update graphical ERD exports:
531
		Go to File > Export > Export as PNG...
532
		Select schemas/vegbien.ERD.png and click Save
533
		Go to File > Export > Export as SVG...
534
		Select schemas/vegbien.ERD.svg and click Save
535
		Go to File > Export > Export as Single Page PDF...
536
		Select schemas/vegbien.ERD.1_pg.pdf and click Save
537
		Go to File > Print...
538
		In the lower left corner, click PDF > Save as PDF...
539
		Set the Title and Author to ""
540
		Select schemas/vegbien.ERD.pdf and click Save
541
		Commit: svn ci -m "schemas/vegbien.ERD.mwb: Regenerated exports"
542
	Refactoring tips:
543
		To rename a table:
544
			In vegbien.sql, do the following:
545
				Replace regexp (?<=_|\b)<old>(?=_|\b) with <new>
546
					This is necessary because the table name is *everywhere*
547
				Search for <new>
548
				Manually change back any replacements inside comments
549
		To rename a column:
550
			Rename the column: ALTER TABLE <table> RENAME <old> TO <new>;
551
			Recreate any foreign key for the column, removing CONSTRAINT <name>
552
				This resets the foreign key name using the new column name
553
	Creating a poster of the ERD:
554
		Determine the poster size:
555
			Measure the line height (from the bottom of one line to the bottom
556
				of another): 16.3cm/24 lines = 0.679cm
557
			Measure the height of the ERD: 35.4cm*2 = 70.8cm
558
			Zoom in as far as possible
559
			Measure the height of a capital letter: 3.5mm
560
			Measure the line height: 8.5mm
561
			Calculate the text's fraction of the line height: 3.5mm/8.5mm = 0.41
562
			Calculate the text height: 0.679cm*0.41 = 0.28cm
563
			Calculate the text height's fraction of the ERD height:
564
				0.28cm/70.8cm = 0.0040
565
			Measure the text height on the *VegBank* ERD poster: 5.5mm = 0.55cm
566
			Calculate the VegBIEN poster height to make the text the same size:
567
				0.55cm/0.0040 = 137.5cm H; *1in/2.54cm = 54.1in H
568
			The ERD aspect ratio is 11 in W x (2*8.5in H) = 11x17 portrait
569
			Calculate the VegBIEN poster width: 54.1in H*11W/17H = 35.0in W
570
			The minimum VegBIEN poster size is 35x54in portrait
571
		Determine the cost:
572
			The FedEx Kinkos near NCEAS (1030 State St, Santa Barbara, CA 93101)
573
				charges the following for posters:
574
				base: $7.25/sq ft
575
				lamination: $3/sq ft
576
				mounting on a board: $8/sq ft
577

    
578
Testing:
579
	On a development machine, you should put the following in your .profile:
580
		umask ug=rwx,o= # prevent files from becoming web-accessible
581
		export log= n=2
582
	For development machine specs, see /planning/resources/dev_machine.specs/
583
	On local machine:
584
	Mapping process: make test
585
		Including column-based import: make test by_col=1
586
			If the row-based and column-based imports produce different inserted
587
			row counts, this usually means that a table is underconstrained
588
			(the unique indexes don't cover all possible rows).
589
			This can occur if you didn't use COALESCE(field, null_value) around
590
			a nullable field in a unique index. See sql_gen.null_sentinels for
591
			the appropriate null value to use.
592
	Map spreadsheet generation: make remake
593
	Missing mappings: make missing_mappings
594
	Everything (for most complete coverage): make test-all
595

    
596
Debugging:
597
	"Binary chop" debugging:
598
		(This is primarily useful for regressions that occurred in a previous
599
		revision, which was committed without running all the tests)
600
		up -r <rev>; make inputs/.TNRS/reinstall; make schemas/public/reinstall; make <failed-test>.xml
601
	.htaccess:
602
		mod_rewrite:
603
			**IMPORTANT**: whenever you change the DirectorySlash setting for a
604
				directory, you *must* clear your browser's cache to ensure that
605
				a cached redirect is not used. this is because RewriteRule
606
				redirects are (by default) temporary, but DirectorySlash
607
				redirects are permanent.
608
				for Firefox:
609
					press Cmd+Shift+Delete
610
					check only Cache
611
					press Enter or click Clear Now
612

    
613
WinMerge setup:
614
	In a Windows VM:
615
	Install WinMerge from <http://winmerge.org/>
616
	Open WinMerge
617
	Go to Edit > Options and click Compare in the left sidebar
618
	Enable "Moved block detection", as described at
619
		<http://manual.winmerge.org/Configuration.html#d0e5892>.
620
	Set Whitespace to Ignore change, as described at
621
		<http://manual.winmerge.org/Configuration.html#d0e5758>.
622

    
623
Documentation:
624
	To generate a Redmine-formatted list of steps for column-based import:
625
		On local machine:
626
		make schemas/public/reinstall
627
		make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
628
	To import and scrub just the test taxonomic names:
629
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo su - aaronmk
630
		inputs/test_taxonomic_names/test_scrub
631

    
632
General:
633
	To see a program's description, read its top-of-file comment
634
	To see a program's usage, run it without arguments
635
	To remake a directory: make <dir>/remake
636
	To remake a file: make <file>-remake
(6-6/11)