Project

General

Profile

1
Installation:
2
	open a terminal window
3
	Check out svn:
4
		sudo apt-get --yes install subversion # not preinstalled on Ubuntu
5
		svn co https://code.nceas.ucsb.edu/code/projects/bien/trunk bien
6
	cd bien/
7
	Install:
8
		**WARNING**: This will delete the public schema of your VegBIEN DB!
9
		# to install a complete DB with all the datasources:
10
			$ make install all=1
11
		# or, to install a blank DB:
12
			$ make install
13
		# at "reload PATH" (if displayed), do what it says
14
		# at "Are you sure you want to continue connecting", type "yes" and
15
			press Enter
16
		# at "aaronmk@jupiter's password", enter the applicable password
17
		# at "[sudo] password for user", enter your password and press Enter
18
		# at "Modifying postgresql.conf and pg_hba.conf", type y and press Enter
19
		# at "kernel.shmmax [...] Press ENTER to continue":
20
			# open a new window
21
			# run what it says
22
			# press Ctrl-D
23
			# return to the previous window
24
			# press Enter
25
		# at "restart PostgreSQL manually ... Press ENTER to continue":
26
			# open a new window
27
			# run what it says
28
			# press Ctrl-D
29
			# return to the previous window
30
			# press Enter
31
		# at "This will delete the current public schema of your VegBIEN DB",
32
			type y and press Enter
33
		# at "If asked for MySQL root password", copy the password to the
34
			clipboard and press Enter
35
		# at "Web server to reconfigure automatically", select apache2 and click
36
			Ok
37
		# at "Configure database for phpmyadmin with dbconfig-common?", click
38
			Yes
39
		# at "Password of the database's administrative user", paste the
40
			password and click Ok
41
		# at "MySQL application password for phpmyadmin", just click Ok
42
		# at "An error occurred while installing the database", click Ok
43
		# at "Next step for database installation", select ignore and click Ok
44
		# at "aaronmk@jupiter's password", enter the applicable password
45
	Uninstall: make uninstall
46
		**WARNING**: This will delete your entire VegBIEN DB!
47
		This includes all archived imports and staging tables.
48

    
49
Connecting to vegbiendev:
50
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
51
	cd /home/bien # should happen automatically at login
52

    
53
Single datasource refresh:
54
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
55
	# -> Maintenance > to back up the vegbiendev databases
56
	# place updated extract in inputs/$datasrc/_src/
57
	# place extracted flat file(s) in the appropriate table subdirs 
58
	rm=1 inputs/<datasrc>/run # reload staging tables
59
	make inputs/<datasrc>/reimport_scrub by_col=1 &
60
		# this works whether or not datasource is already imported
61
	tail -150 inputs/<datasrc>/*/logs/public.log.sql # view progress
62
	# -> Full database import > To re-run geoscrubbing
63
	# -> Full database import > To remake analytical DB
64
	# -> Full database import > To back up DB
65
	# -> Maintenance > to back up the vegbiendev databases
66

    
67
datasource removal:
68
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
69
	$ make inputs/$datasrc/rm # runtime: see
70
		# http://vegpath.org/wiki/Individual_datasource_refresh#datasource-removal-runtimes
71

    
72
Notes on system stability:
73
	**WARNING**: when shutting down the VM, always first stop Postgres:
74
		sudo service postgresql stop
75
		this prevents the OS from SIGKILLing Postgres, which sometimes causes
76
		database corruption 
77

    
78
Notes on running programs:
79
	**WARNING**: always start with a clean shell, to avoid spurious bugs. the
80
		shell should not have changes to the env vars. (there have been bugs
81
		that went away after closing and reopening the terminal window.) note
82
		that running `exec bash` is not sufficient to *reset* the env vars.
83

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

    
89
Full database import:
90
	**WARNING**: You must perform *every single* step listed below, to avoid
91
		breaking column-based import
92
	**WARNING**: always start with a clean shell, as described above under
93
		"Notes on running programs"
94
	**IMPORTANT**: the beginning of the import should be scheduled at a time
95
		when the DB will not be needed for other uses. this is necessary because
96
		vegbiendev will be slow for the first few hours of the import, due to
97
		the import using all the available cores.
98
	do steps under Maintenance > "to synchronize vegbiendev, jupiter, and
99
		your local machine"
100
	On local machine:
101
		make inputs/upload
102
		make inputs/upload live=1
103
		make test by_col=1 # runtime: 1 h ("53m7.383s") @starscream
104
			if you encounter errors, they are most likely related to the
105
				PostgreSQL error parsing in /lib/sql.py parse_exception()
106
			See note under Testing below
107
	-> Maintenance > to back up the vegbiendev databases > back up Postgres
108
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
109
	Ensure there are no local modifications: svn st
110
	up
111
	make inputs/download
112
	make inputs/download live=1
113
	For each newly-uploaded datasource above: make inputs/<datasrc>/reinstall
114
	Update the auxiliary schemas: make schemas/reinstall
115
		**WARNING**: requires sudo access!
116
		The public schema will be installed separately by the import process
117
	Delete imports before the last so they won't bloat the full DB backup:
118
		make backups/vegbien.<version>.backup/remove
119
		To keep a previous import other than the public schema:
120
			export dump_opts='--exclude-schema=public --exclude-schema=<version>'
121
			# env var will be inherited by `screen` shell
122
	restart Postgres to free up any disk space used by temp tables from the last
123
		import (this is apparently not automatically reclaimed):
124
		make postgres_restart
125
	Make sure there is at least 1 TB of disk space on /: df -h
126
		although the import schema itself is only 315 GB, Postgres uses
127
			significant temporary space at the beginning of the import.
128
			the total disk usage oscillates between 1.2 TB and the entire disk
129
			for the first day (for import started @12:55:09, high-water marks of
130
			1.7 TB @14:00:25, 1.8 TB @15:38:32; then next day w/ 2 datasources
131
			running: entire disk for 4 min @05:35:44, 1.8 TB @11:15:05).
132
		To free up space, remove backups that have been archived on jupiter:
133
			List backups/ to view older backups
134
			Check their MD5 sums using the steps under On jupiter below
135
			Remove these backups
136
	unlock hardlinked files:
137
		$ chmod ug+w inputs/{.[^as.],}*/*/{map.csv,new_terms.csv,unmapped_terms.csv}
138
	for full import:
139
		screen
140
		Press ENTER
141
		unset TMOUT # TMOUT causes shell to exit even with background processes
142
	$0 # nested shell to prevent errexit from closing the window
143
	the following must happen within screen to avoid affecting the outer shell:
144
	unset TMOUT # TMOUT causes shell to exit even with background processes
145
	set -o ignoreeof # prevent Ctrl+D from exiting shell to keep attached jobs
146
	on local machine:
147
		unset n # clear any limit set in .profile (unless desired)
148
		unset log # allow logging output to go to log files
149
	unset version # clear any version from last import, etc.
150
	if no commits have been made since the last import (eg. if retrying an
151
		import), set a custom version that differs from the auto-assigned one
152
		(would otherwise cause a collision with the last import):
153
		svn info
154
		extract the svn revision after "Revision:"
155
		export version=r[revision]_2 # +suffix to distinguish from last import
156
			# env var will be inherited by `screen` shell
157
	to import just a subset of the datasources:
158
		declare -ax inputs; inputs=(inputs/{src,...}/) # no () in declare on Mac
159
			# array vars *not* inherited by `screen` shell
160
		export version=custom_import_name
161
	Start column-based import: . bin/import_all
162
		To use row-based import: . bin/import_all by_col=
163
		To stop all running imports: . bin/stop_imports
164
		**WARNING**: Do NOT run import_all in the background, or the jobs it
165
			creates won't be owned by your shell.
166
		Note that import_all will take up to an hour to import the NCBI backbone
167
			and other metadata before returning control to the shell.
168
		To view progress:
169
			tail inputs/{.[^as.],}*/*/logs/$version.log.sql
170
	note: at the beginning of the import, the system may send out CPU load
171
		warning e-mails. these can safely be ignored. (they happen because the
172
		parallel imports use all the available cores.)
173
	for test import, turn off DB backup (also turns off analytical DB creation):
174
		kill % # cancel after_import()
175
	Wait (4 days) for the import to finish
176
	**WARNING**: do *not* run backups/pg_snapshot while the import is running,
177
		due to continuously-changing files
178
	**WARNING**: do *not* run backups/pg_snapshot until the previous import has
179
		been replaced, to avoid running into disk space limits
180
	To recover from a closed terminal window: screen -r
181
	To restart an aborted import for a specific table:
182
		export version=<version>
183
		(set -o errexit; make inputs/<datasrc>/<table>/import_scrub by_col=1 continue=1; make inputs/<datasrc>/publish) &
184
		bin/after_import $! & # $! can also be obtained from `jobs -l`
185
	Get $version: echo $version
186
	Set $version in all vegbiendev terminals: export version=<version>
187
	When there are no more running jobs, exit `screen`: exit # not Ctrl+D
188
	upload logs: make inputs/upload live=1
189
	On local machine: make inputs/download-logs live=1
190
	check for disk space errors:
191
		grep --files-with-matches -F 'No space left on device' inputs/{.[^as.],}*/*/logs/$version.log.sql
192
		if there are any matches:
193
			manually reimport these datasources using the steps under
194
				Single datasource import
195
			bin/after_import &
196
			wait for the import to finish
197
	tail inputs/{.[^as.],}*/*/logs/$version.log.sql
198
	In the output, search for "Command exited with non-zero status"
199
	For inputs that have this, fix the associated bug(s)
200
	If many inputs have errors, discard the current (partial) import:
201
		make schemas/$version/uninstall
202
	Otherwise, continue
203
	In PostgreSQL:
204
		Go to wiki.vegpath.org/VegBIEN_contents
205
		Get the # observations
206
		Get the # datasources
207
		Get the # datasources with observations
208
		in the r# schema:
209
		Check that analytical_stem contains [# observations] rows
210
		Check that source contains the following datasources (note that
211
			refreshed datasources will be at the end):
212
			geoscrub herbaria IRMNG IUCN NCBI newWorld TNRS ACAD ARIZ bien_web
213
			BRIT CTFS GBIF HIBG JBM Madidi MO MT NCU NVS NY QFA REMIB
214
			SpeciesLink TEAM test_taxonomic_names TRT TRTE U UBC UNCC VASCAN WIN
215
			XAL
216
		Check that provider_count contains [# datasources with observations]
217
			rows with dataset="(total)" (at the top when the table is unsorted)
218
	Check that TNRS ran successfully:
219
		tail -100 inputs/.TNRS/tnrs/logs/tnrs.make.log.sql
220
		If the log ends in an AssertionError
221
			"assert sql.table_col_names(db, table) == header":
222
			Figure out which TNRS CSV columns have changed
223
			On local machine:
224
				Make the changes in the DB's TNRS and public schemas
225
				rm=1 inputs/.TNRS/schema.sql.run export_
226
				make schemas/remake
227
				inputs/test_taxonomic_names/test_scrub # re-run TNRS
228
				rm=1 inputs/.TNRS/data.sql.run export_
229
				Commit
230
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
231
				If dropping a column, save the dependent views
232
				Make the same changes in the live TNRS.tnrs table on vegbiendev
233
				If dropping a column, recreate the dependent views
234
				Restart the TNRS client: make scrub by_col=1 &
235
	Publish the new import:
236
		**WARNING**: Before proceeding, be sure you have done *every single*
237
			verification step listed above. Otherwise, a previous valid import
238
			could incorrectly be overwritten with a broken one.
239
		make schemas/$version/publish # runtime: 1 min ("real 1m10.451s")
240
	unset version
241
	make backups/upload live=1
242
	on local machine:
243
		make backups/vegbien.$version.backup/download live=1
244
			# download backup to local machine
245
	ssh aaronmk@jupiter.nceas.ucsb.edu
246
		cd /data/dev/aaronmk/bien/backups
247
		For each newly-archived backup:
248
			make -s <backup>.md5/test
249
			Check that "OK" is printed next to the filename
250
	If desired, record the import times in inputs/import.stats.xls:
251
		On local machine:
252
		Open inputs/import.stats.xls
253
		click the "current" tab
254
		If the rightmost import is within 5 columns of column IV:
255
			Copy the current tab to <leftmost-date>~<rightmost-date>
256
			Remove the previous imports from the current tab because they are
257
				now in the copied tab instead
258
		Insert a copy of the leftmost "By column" column group before it
259
		export version=<version>
260
		bin/import_date inputs/{.[^as.],}*/*/logs/$version.log.sql
261
		Update the import date in the upper-right corner
262
		bin/import_times inputs/{.[^as.],}*/*/logs/$version.log.sql
263
		Paste the output over the # Rows/Time columns, making sure that the
264
			row counts match up with the previous import's row counts
265
		If the row counts do not match up, insert or reorder rows as needed
266
			until they do. Get the datasource names from the log file footers:
267
			tail inputs/{.[^as.],}*/*/logs/$version.log.sql
268
		update the Postprocessing times:
269
			analytical DB remake time:
270
				from the end of inputs/analytical_db/logs/make_analytical_db.log.sql,
271
					search upwards for "_individual_view_modify" followed by a
272
					line of -'s
273
				enter as: =[ms]/1000/3600/24
274
		Commit: svn ci -m 'inputs/import.stats.xls: updated import times'
275
	Running individual steps separately:
276
	To run TNRS:
277
		To use an import other than public: export version=<version>
278
		to rescrub all names:
279
			make inputs/.TNRS/reinstall
280
			re-create public-schema views that were cascadingly deleted
281
		make scrub &
282
		To view progress:
283
			tail -100 inputs/.TNRS/tnrs/logs/tnrs.make.log.sql
284
	To re-run geoscrubbing:
285
		$ screen
286
		# press Enter
287
		$ unset TMOUT # TMOUT causes shell to exit even with background processes
288
		# to use an import other than public: $ export version=<version>
289
		$ bin/psql_verbose_vegbien <<<'SELECT geoscrub_input_view_modify();' &
290
			# runtime: 6 min ("6:02.30") @r14827 @vegbiendev
291
		# wait until done
292
		$ rm=1 exports/geoscrub_input.csv.run
293
			# runtime: 1 min ("1m2.962s") @r14827 @vegbiendev
294
		$ $0 # subshell to avoid closing screen on errexit
295
		$ rm=1 inputs/.geoscrub/geoscrub_output/geoscrub.csv.run &
296
			# runtime: 1.5 h ("84m55.408s") @r14827 @vegbiendev
297
		# wait until done
298
		$ rm=1 inputs/.geoscrub/geoscrub_output/run &
299
			# runtime: 12 min ("11m35.693s") @r14827 @vegbiendev
300
		# wait until done
301
		# re-create public-schema views that were cascadingly deleted (currently
302
			plot.**, view_full_occurrence_individual_view, geoscrub_input_new)
303
		# press Ctrl+D
304
		# remake the analytical DB (below)
305
	To remake analytical DB:
306
		To use an import other than public: export version=<version>
307
		bin/make_analytical_db & # runtime: 13 h ("12:43:57elapsed")
308
		To view progress:
309
			tail -150 inputs/analytical_db/logs/make_analytical_db.log.sql
310
	To back up DB (staging tables and last import):
311
		To use an import *other than public*: export version=<version>
312
		make backups/TNRS.backup-remake &
313
		dump_opts=--exclude-schema=public make backups/vegbien.$version.backup/test &
314
			If after renaming to public, instead set dump_opts='' and replace
315
			$version with the appropriate revision
316
		make backups/upload live=1
317

    
318
Datasource setup:
319
	On local machine:
320
	Example steps for a datasource: wiki.vegpath.org/Import_process_for_Madidi
321
	umask ug=rwx,o= # prevent files from becoming web-accessible
322
	Add a new datasource: make inputs/<datasrc>/add
323
		<datasrc> may not contain spaces, and should be abbreviated.
324
		If the datasource is a herbarium, <datasrc> should be the herbarium code
325
			as defined by the Index Herbariorum <http://sweetgum.nybg.org/ih/>
326
	For a new-style datasource (one containing a ./run runscript):
327
		"cp" -f inputs/.NCBI/{Makefile,run,table.run} inputs/<datasrc>/
328
	For MySQL inputs (exports and live DB connections):
329
		For .sql exports:
330
			Place the original .sql file in _src/ (*not* in _MySQL/)
331
			Follow the steps starting with Install the staging tables below.
332
				This is for an initial sync to get the file onto vegbiendev.
333
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
334
				Create a database for the MySQL export in phpMyAdmin
335
				Give the bien user all database-specific privileges *except*
336
					UPDATE, DELETE, ALTER, DROP. This prevents bugs in the
337
					import scripts from accidentally deleting data.
338
				bin/mysql_bien database <inputs/<datasrc>/_src/export.sql &
339
		mkdir inputs/<datasrc>/_MySQL/
340
		cp -p lib/MySQL.{data,schema}.sql.make inputs/<datasrc>/_MySQL/
341
		Edit _MySQL/*.make for the DB connection
342
			For a .sql export, use server=vegbiendev and --user=bien
343
		Skip the Add input data for each table section
344
	For MS Access databases:
345
		Place the .mdb or .accdb file in _src/
346
		Download and install Bullzip's MS Access to PostgreSQL from
347
			http://bullzip.com/download.php > Access To PostgreSQL > Download
348
		Use Access To PostgreSQL to export the database:
349
			Export just the tables/indexes to inputs/<datasrc>/<file>.schema.sql
350
				using the settings in the associated .ini file where available
351
			Export just the data to inputs/<datasrc>/<file>.data.sql using the
352
				settings in the associated .ini file where available
353
		In <file>.schema.sql, make the following changes:
354
			Replace text "^CREATE DATABASE .*?;$" with "/*$0*/"
355
			Replace text "BOOLEAN" with "/*BOOLEAN*/INTEGER"
356
			Replace text "DOUBLE PRECISION NULL" with "DOUBLE PRECISION"
357
		Skip the Add input data for each table section
358
	Add input data for each table present in the datasource:
359
		For .sql exports, you must use the name of the table in the DB export
360
		For CSV files, you can use any name. It's recommended to use a table
361
			name from <https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCSV#Suggested-table-names>
362
		Note that if this table will be joined together with another table, its
363
			name must end in ".src"
364
		make inputs/<datasrc>/<table>/add
365
			Important: DO NOT just create an empty directory named <table>!
366
				This command also creates necessary subdirs, such as logs/.
367
		If the table is in a .sql export: make inputs/<datasrc>/<table>/install
368
			Otherwise, place the CSV(s) for the table in
369
			inputs/<datasrc>/<table>/ OR place a query joining other tables
370
			together in inputs/<datasrc>/<table>/create.sql
371
		Important: When exporting relational databases to CSVs, you MUST ensure
372
			that embedded quotes are escaped by doubling them, *not* by
373
			preceding them with a "\" as is the default in phpMyAdmin
374
		If there are multiple part files for a table, and the header is repeated
375
			in each part, make sure each header is EXACTLY the same.
376
			(If the headers are not the same, the CSV concatenation script
377
			assumes the part files don't have individual headers and treats the
378
			subsequent headers as data rows.)
379
		Add <table> to inputs/<datasrc>/import_order.txt before other tables
380
			that depend on it
381
		For a new-style datasource:
382
			"cp" -f inputs/.NCBI/nodes/run inputs/<datasrc>/<table>/
383
			inputs/<datasrc>/<table>/run
384
	Install the staging tables:
385
		make inputs/<datasrc>/reinstall quiet=1 &
386
		For a MySQL .sql export:
387
			At prompt "[you]@vegbiendev's password:", enter your password
388
			At prompt "Enter password:", enter the value in config/bien_password
389
		To view progress: tail -f inputs/<datasrc>/<table>/logs/install.log.sql
390
		View the logs: tail -n +1 inputs/<datasrc>/*/logs/install.log.sql
391
			tail provides a header line with the filename
392
			+1 starts at the first line, to show the whole file
393
		For every file with an error 'column "..." specified more than once':
394
			Add a header override file "+header.<ext>" in <table>/:
395
				Note: The leading "+" should sort it before the flat files.
396
					"_" unfortunately sorts *after* capital letters in ASCII.
397
				Create a text file containing the header line of the flat files
398
				Add an ! at the beginning of the line
399
					This signals cat_csv that this is a header override.
400
				For empty names, use their 0-based column # (by convention)
401
				For duplicate names, add a distinguishing suffix
402
				For long names that collided, rename them to <= 63 chars long
403
				Do NOT make readability changes in this step; that is what the
404
					map spreadsheets (below) are for.
405
				Save
406
		If you made any changes, re-run the install command above
407
	Auto-create the map spreadsheets: make inputs/<datasrc>/
408
	Map each table's columns:
409
		In each <table>/ subdir, for each "via map" map.csv:
410
			Open the map in a spreadsheet editor
411
			Open the "core map" /mappings/Veg+-VegBIEN.csv
412
			In each row of the via map, set the right column to a value from the
413
				left column of the core map
414
			Save
415
		Regenerate the derived maps: make inputs/<datasrc>/
416
	Accept the test cases:
417
		For a new-style datasource:
418
			inputs/<datasrc>/run
419
			svn di inputs/<datasrc>/*/test.xml.ref
420
			If you get errors, follow the steps for old-style datasources below
421
		For an old-style datasource:
422
			make inputs/<datasrc>/test
423
			When prompted to "Accept new test output", enter y and press ENTER
424
			If you instead get errors, do one of the following for each one:
425
			-	If the error was due to a bug, fix it
426
			-	Add a SQL function that filters or transforms the invalid data
427
			-	Make an empty mapping for the columns that produced the error.
428
				Put something in the Comments column of the map spreadsheet to
429
				prevent the automatic mapper from auto-removing the mapping.
430
			When accepting tests, it's helpful to use WinMerge
431
				(see WinMerge setup below for configuration)
432
		make inputs/<datasrc>/test by_col=1
433
			If you get errors this time, this always indicates a bug, usually in
434
				the VegBIEN unique constraints or column-based import itself
435
	Add newly-created files: make inputs/<datasrc>/add
436
	Commit: svn ci -m "Added inputs/<datasrc>/" inputs/<datasrc>/
437
	Update vegbiendev:
438
		ssh aaronmk@jupiter.nceas.ucsb.edu
439
			up
440
		On local machine:
441
			./fix_perms
442
			make inputs/upload
443
			make inputs/upload live=1
444
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
445
			up
446
			make inputs/download
447
			make inputs/download live=1
448
			Follow the steps under Install the staging tables above
449

    
450
Maintenance:
451
	on a live machine, you should put the following in your .profile:
452
--
453
# make svn files web-accessible. this does not affect unversioned files, because
454
# these get the right permissions on the local machine instead.
455
umask ug=rwx,o=rx
456

    
457
unset TMOUT # TMOUT causes screen to exit even with background processes
458
--
459
	if http://vegbiendev.nceas.ucsb.edu/phppgadmin/ goes down:
460
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
461
			make phppgadmin-Linux
462
	regularly, re-run full-database import so that bugs in it don't pile up.
463
		it needs to be kept in working order so that it works when it's needed.
464
	to back up the vegbiendev databases:
465
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
466
		back up MySQL: # usually few changes, so do this first
467
			backups/mysql_snapshot
468
			l=1        overwrite=1 inplace=1 local_dir=/ remote_url="$USER@jupiter:/data/dev/aaronmk/Documents/BIEN/" subpath=/var/lib/mysql.bak/ sudo -E env PATH="$PATH" bin/sync_upload
469
			on local machine:
470
			l=1 swap=1 overwrite=1 inplace=1 local_dir=~ sync_remote_subdir=                          subpath=~/Documents/BIEN/var/lib/mysql.bak/                          bin/sync_upload
471
		back up Postgres:
472
			$ screen
473
			# press Enter
474
			$ unset TMOUT # TMOUT causes shell to exit even with background processes
475
			$ backups/pg_snapshot # runtime when queries have been run: 1 h ("64m11.586s")
476
	to synchronize vegbiendev, jupiter, and your local machine:
477
		**WARNING**: pay careful attention to all files that will be deleted or
478
			overwritten!
479
		install put if needed:
480
			download https://uutils.googlecode.com/svn/trunk/bin/put to ~/bin/ and `chmod +x` it
481
		when changes are made on vegbiendev:
482
			avoid extraneous diffs when rsyncing:
483
				on local machine:
484
					up; ./fix_perms
485
				ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
486
					up; ./fix_perms
487
				ssh aaronmk@jupiter.nceas.ucsb.edu
488
					up; ./fix_perms
489
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
490
				upload:
491
				del=1 bin/sync_upload --size-only
492
					then review diff, and rerun with `l=1` prepended
493
			on your machine:
494
				download:
495
				overwrite=1 swap=1 src=. dest='aaronmk@jupiter.nceas.ucsb.edu:~/bien' put --exclude=.svn web/BIEN3/TWiki; ./fix_perms
496
					then review diff, and rerun with `l=1` prepended
497
				swap=1 bin/sync_upload backups/TNRS.backup
498
					then review diff, and rerun with `l=1` prepended
499
				del=1 swap=1 bin/sync_upload --size-only
500
					then review diff, and rerun with `l=1` prepended
501
				sync_remote_url=~/Dropbox/svn/ bin/sync_upload --existing --size-only --no-perms
502
					# --size-only: just update mtimes
503
					# --no-perms: don't transfer the hardlink lock status
504
					# no overwrite=1: preserve uncommitted changes
505
					then review diff, and rerun with `l=1` prepended
506
	to back up e-mails:
507
		on local machine:
508
		/Applications/gmvault-v1.8.1-beta/bin/gmvault sync --multiple-db-owner --type quick aaronmk.nceas@gmail.com
509
		open Thunderbird
510
		click the All Mail folder for each account and wait for it to download the e-mails in it
511
	to back up the version history:
512
		# back up first on the local machine, because often only the svnsync
513
			command gets run, and that way it will get backed up immediately to
514
			Dropbox (and hourly to Time Machine), while vegbiendev only gets
515
			backed up daily to tape
516
		on local machine:
517
		svnsync sync file://"$HOME"/Dropbox/docs/BIEN/svn_repo/ # initial runtime: 1.5 h ("08:21:38" - "06:45:26") @vegbiendev
518
		(cd ~/Dropbox/docs/BIEN/git/; git svn fetch)
519
		# use absolute path for vegbiendev commands because the Ubuntu 14.04
520
			version of rsync doesn't expand ~ properly
521
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:/data/dev/aaronmk/' put Dropbox/docs/BIEN/svn_repo/ # runtime: 1 min ("1:05.08")
522
			then review diff, and rerun with `l=1` prepended
523
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:/data/dev/aaronmk/' put Dropbox/docs/BIEN/git/
524
			then review diff, and rerun with `l=1` prepended
525
	to back up vegbiendev:
526
		do steps under Maintenance > "to synchronize vegbiendev, jupiter, and
527
			your local machine"
528
		on local machine:
529
			# **IMPORTANT**: can't use inplace=1 optimization because this
530
			#  messes up the shared hardlinks used by
531
			#  ~/Documents/BIEN/vegbiendev.2014-2-2_1-07-32PT*/
532
			l=1 overwrite=1 src=root@vegbiendev.nceas.ucsb.edu:/ dest=~/Documents/BIEN/vegbiendev/ sudo -E put --exclude=/var/lib/mysql.bak --exclude=/var/lib/postgresql.bak --exclude='/var/lib/postgresql/9.3/main/*/' --exclude=/home/aaronmk/bien
533
			# enable --link-dest to work:
534
				chmod -R o+r ~/bien/.svn/; find ~/bien/.svn -type d -exec chmod o+rx {} \; # match perms
535
				l=1 overwrite=1 del= src='aaronmk@vegbiendev.nceas.ucsb.edu:~/bien/' dest=~/bien/ put --existing --size-only .svn/pristine/ # match times and perms
536
			l=1 overwrite=1 src=aaronmk@vegbiendev.nceas.ucsb.edu:/ dest=~/Documents/BIEN/vegbiendev/ sudo -E put --link-dest="$HOME"/Documents/BIEN/svn/ --no-owner --no-group home/aaronmk/bien/
537
				# --no-owner --no-group: needed to allow --link-dest to work
538
				# --link-dest: relative to dest, not currdir, so need abs path
539
			./fix_perms # lock hardlinked files
540
	to back up the local machine's settings:
541
		do step when changes are made on vegbiendev > on your machine, download
542
		ssh aaronmk@jupiter.nceas.ucsb.edu
543
			(cd ~/Dropbox/svn/; up)
544
		on your machine:
545
			sudo find / -name .DS_Store -print -delete # runtime: 23 min ("04:01:28" - "03:39:10")
546
			rm ~/'Library/Thunderbird/Profiles/9oo8rcyn.default/ImapMail/imap.googlemail.com/[Gmail].sbd/Spam'
547
				# remove the downloaded Spam folder, because spam e-mails often contain viruses that would trigger clamscan
548
			overwrite=1           sync_local_dir=~/Dropbox/svn/ sync_remote_subdir=Dropbox/svn/ bin/sync_upload --size-only # just update mtimes
549
				then review diff, and rerun with `l=1` prepended
550
			overwrite=1 inplace=1 sync_local_dir=~/             sync_remote_subdir=             bin/sync_upload ~/"VirtualBox VMs/**" # need inplace=1 because they are very large files
551
				then review diff, and rerun with `l=1` prepended
552
			overwrite=1           sync_local_dir=~/             sync_remote_subdir= sudo -E     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" --exclude="/software/**/.svn/"
553
				# sudo -E: needed for Documents/BIEN/vegbiendev*/
554
				then review diff, and rerun with `l=1` prepended
555
			pause Dropbox: system tray > Dropbox icon > gear icon > Pause Syncing
556
				this prevents Dropbox from trying to capture filesystem
557
				events while syncing
558
			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=/gmvault-db/ --exclude="/software/" --exclude="/VirtualBox VMs/**.sav" --exclude="/VirtualBox VMs/**.vdi" --exclude="/VirtualBox VMs/**.vmdk"
559
				then review diff, and rerun with `l=1` prepended
560
			resume Dropbox: system tray > Dropbox icon > gear icon > Resume Syncing
561
			l=1 overwrite=1 src=/ dest=root@vegbiendev.nceas.ucsb.edu:/home/aaronmk/Documents/BIEN/frenzy/ sudo -E put --exclude=/.fseventsd/ --exclude=/private/var/vm/ --exclude="$HOME"/ --exclude=/usr/local/var/postgres/
562
				# --exclude="$HOME"/: saves 466 GB
563
				# --exclude=/usr/local/var/postgres/: saves 60 GB
564
				# total size: 58 GB (584 GB - (466 GB + 60 GB))
565
	to backup files not in Time Machine:
566
		**IMPORTANT**: need to use 2 TB external hard drive instead of Time
567
			Machine drive because Time Machine drive does not have
568
			~/Documents/BIEN/ in a location where it can be hardlinked against
569
		On local machine:
570
		on first run, create parent dirs:
571
			sudo mkdir -p '/Volumes/BIEN3.**SAVE**/Users/aaronmk/Documents/BIEN/'
572
			sudo mkdir -p '/Volumes/BIEN3.**SAVE**/usr/local/var/postgres/'
573
			l=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --existing
574
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --include='/vegbiendev**' --exclude='**' Users/aaronmk/Documents/BIEN/
575
			# this cannot be backed up by Time Machine because it dereferences hard links:
576
			#  `sudo find /Volumes/Time\ Machine\ Backups/Backups.backupdb/ ! -type d -links +1`
577
			#  returns no files when there is a single timestamped backup, but
578
			#  `sudo find / ! -type d -links +1` does
579
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put usr/local/var/postgres/
580
			# this cannot be backed up by Time Machine because it prevents the backup process from ending
581
		brew services stop postgresql # if doesn't work, run `rm /usr/local/var/postgres/postmaster.pid` and retry
582
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put usr/local/var/postgres/
583
		brew services start postgresql # if doesn't work, run `rm /usr/local/var/postgres/postmaster.pid` and retry
584
	to back up the local machine's hard drive:
585
		turn on and connect the 2 TB external hard drive
586
		# open "/Applications/Utilities/Disk Utility.app"
587
		# resize the BIEN3.**SAVE** partition so there is enough space
588
		screen
589
		# --exclude='/\**': exclude *-files indicating the (differing) retention
590
		#  statuses of the partitions involved
591
		# don't need to pause Dropbox, since it will be reinitialized for the
592
		#  new partition UUID anyway
593
		# **IMPORTANT**: turn off Time Machine. this prevents Time Machine from
594
		#  running when the backup is booted, which messes up the Time Machine
595
		#  backup because the partition UUID is different.
596
		brew services stop postgresql # if doesn't work, run `rm /usr/local/var/postgres/postmaster.pid` and retry
597
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --exclude='/\**' --exclude=/.fseventsd/ --exclude=/private/var/vm/
598
			# no --extended-attributes: rsync has to visit every file for this
599
			# runtime: 10 min (~600); initial runtime: 4-13 h ("2422.84"+"12379.91" .. "45813.19"+"747.96")
600
		brew services start postgresql # if doesn't work, run `rm /usr/local/var/postgres/postmaster.pid` and retry
601
		# turn on Time Machine
602
	to restore from Time Machine:
603
		# restart holding Alt
604
		# select Time Machine Backups
605
		# restore the last Time Machine backup to Macintosh HD
606
		# restart holding Alt
607
		# select Macintosh HD
608
		$ screen
609
		$ l=1 swap=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ sudo -E put usr/local/var/postgres/ # runtime: 1 h ("4020.61")
610
		$ make postgres_restart
611
	VegCore data dictionary:
612
		Regularly, or whenever the VegCore data dictionary page
613
			(https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore)
614
			is changed, regenerate mappings/VegCore.csv:
615
			On local machine:
616
			make mappings/VegCore.htm-remake; make mappings/
617
			apply new data dict mappings to datasource mappings/staging tables:
618
				inputs/run postprocess # runtime: see inputs/run
619
				time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
620
			svn di mappings/VegCore.tables.redmine
621
			If there are changes, update the data dictionary's Tables section
622
			When moving terms, check that no terms were lost: svn di
623
			svn ci -m 'mappings/VegCore.htm: regenerated from wiki'
624
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
625
				perform the steps under "apply new data dict mappings to
626
					datasource mappings/staging tables" above
627
	Important: Whenever you install a system update that affects PostgreSQL or
628
		any of its dependencies, such as libc, you should restart the PostgreSQL
629
		server. Otherwise, you may get strange errors like "the database system
630
		is in recovery mode" which go away upon reimport, or you may not be able
631
		to access the database as the postgres superuser. This applies to both
632
		Linux and Mac OS X.
633

    
634
Backups:
635
	Archived imports:
636
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
637
		Back up: make backups/<version>.backup &
638
			Note: To back up the last import, you must archive it first:
639
				make schemas/rotate
640
		Test: make -s backups/<version>.backup/test &
641
		Restore: make backups/<version>.backup/restore &
642
		Remove: make backups/<version>.backup/remove
643
		Download: make backups/<version>.backup/download
644
	TNRS cache:
645
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
646
		Back up: make backups/TNRS.backup-remake &
647
			runtime: 3 min ("real 2m48.859s")
648
		Restore:
649
			yes|make inputs/.TNRS/uninstall
650
			make backups/TNRS.backup/restore &
651
				runtime: 5.5 min ("real 5m35.829s")
652
			yes|make schemas/public/reinstall
653
				Must come after TNRS restore to recreate tnrs_input_name view
654
	Full DB:
655
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
656
		Back up: make backups/vegbien.<version>.backup &
657
		Test: make -s backups/vegbien.<version>.backup/test &
658
		Restore: make backups/vegbien.<version>.backup/restore &
659
		Download: make backups/vegbien.<version>.backup/download
660
	Import logs:
661
		On local machine:
662
		Download: make inputs/download-logs live=1
663

    
664
Datasource refreshing:
665
	VegBank:
666
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
667
		make inputs/VegBank/vegbank.sql-remake
668
		make inputs/VegBank/reinstall quiet=1 &
669

    
670
Schema changes:
671
	On local machine:
672
	When changing the analytical views, run sync_analytical_..._to_view()
673
		to update the corresponding table
674
	Remember to update the following files with any renamings:
675
		schemas/filter_ERD.csv
676
		mappings/VegCore-VegBIEN.csv
677
		mappings/verify.*.sql
678
	Regenerate schema from installed DB: make schemas/remake
679
	Reinstall DB from schema: make schemas/public/reinstall schemas/reinstall
680
		**WARNING**: This will delete the public schema of your VegBIEN DB!
681
	If needed, reinstall staging tables:
682
		On local machine:
683
			sudo -E -u postgres psql <<<'ALTER DATABASE vegbien RENAME TO vegbien_prev'
684
			make db
685
			. bin/reinstall_all
686
			Fix any bugs and retry until no errors
687
			make schemas/public/install
688
				This must be run *after* the datasources are installed, because
689
				views in public depend on some of the datasources
690
			sudo -E -u postgres psql <<<'DROP DATABASE vegbien_prev'
691
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
692
			repeat the above steps
693
			**WARNING**: Do not run this until reinstall_all runs successfully
694
			on the local machine, or the live DB may be unrestorable!
695
	update mappings and staging table column names:
696
		on local machine:
697
			inputs/run postprocess # runtime: see inputs/run
698
			time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
699
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
700
			manually apply schema changes to the live public schema
701
			do steps under "on local machine" above
702
	Sync ERD with vegbien.sql schema:
703
		Run make schemas/vegbien.my.sql
704
		Open schemas/vegbien.ERD.mwb in MySQLWorkbench
705
		Go to File > Export > Synchronize With SQL CREATE Script...
706
		For Input File, select schemas/vegbien.my.sql
707
		Click Continue
708
		In the changes list, select each table with an arrow next to it
709
		Click Update Model
710
		Click Continue
711
		Note: The generated SQL script will be empty because we are syncing in
712
			the opposite direction
713
		Click Execute
714
		Reposition any lines that have been reset
715
		Add any new tables by dragging them from the Catalog in the left sidebar
716
			to the diagram
717
		Remove any deleted tables by right-clicking the table's diagram element,
718
			selecting Delete '<table name>', and clicking Delete
719
		Save
720
		If desired, update the graphical ERD exports (see below)
721
	Update graphical ERD exports:
722
		Go to File > Export > Export as PNG...
723
		Select schemas/vegbien.ERD.png and click Save
724
		Go to File > Export > Export as SVG...
725
		Select schemas/vegbien.ERD.svg and click Save
726
		Go to File > Export > Export as Single Page PDF...
727
		Select schemas/vegbien.ERD.1_pg.pdf and click Save
728
		Go to File > Print...
729
		In the lower left corner, click PDF > Save as PDF...
730
		Set the Title and Author to ""
731
		Select schemas/vegbien.ERD.pdf and click Save
732
		Commit: svn ci -m "schemas/vegbien.ERD.mwb: Regenerated exports"
733
	Refactoring tips:
734
		To rename a table:
735
			In vegbien.sql, do the following:
736
				Replace regexp (?<=_|\b)<old>(?=_|\b) with <new>
737
					This is necessary because the table name is *everywhere*
738
				Search for <new>
739
				Manually change back any replacements inside comments
740
		To rename a column:
741
			Rename the column: ALTER TABLE <table> RENAME <old> TO <new>;
742
			Recreate any foreign key for the column, removing CONSTRAINT <name>
743
				This resets the foreign key name using the new column name
744
	Creating a poster of the ERD:
745
		Determine the poster size:
746
			Measure the line height (from the bottom of one line to the bottom
747
				of another): 16.3cm/24 lines = 0.679cm
748
			Measure the height of the ERD: 35.4cm*2 = 70.8cm
749
			Zoom in as far as possible
750
			Measure the height of a capital letter: 3.5mm
751
			Measure the line height: 8.5mm
752
			Calculate the text's fraction of the line height: 3.5mm/8.5mm = 0.41
753
			Calculate the text height: 0.679cm*0.41 = 0.28cm
754
			Calculate the text height's fraction of the ERD height:
755
				0.28cm/70.8cm = 0.0040
756
			Measure the text height on the *VegBank* ERD poster: 5.5mm = 0.55cm
757
			Calculate the VegBIEN poster height to make the text the same size:
758
				0.55cm/0.0040 = 137.5cm H; *1in/2.54cm = 54.1in H
759
			The ERD aspect ratio is 11 in W x (2*8.5in H) = 11x17 portrait
760
			Calculate the VegBIEN poster width: 54.1in H*11W/17H = 35.0in W
761
			The minimum VegBIEN poster size is 35x54in portrait
762
		Determine the cost:
763
			The FedEx Kinkos near NCEAS (1030 State St, Santa Barbara, CA 93101)
764
				charges the following for posters:
765
				base: $7.25/sq ft
766
				lamination: $3/sq ft
767
				mounting on a board: $8/sq ft
768

    
769
Testing:
770
	On a development machine, you should put the following in your .profile:
771
		umask ug=rwx,o= # prevent files from becoming web-accessible
772
		export log= n=2
773
	For development machine specs, see /planning/resources/dev_machine.specs/
774
	On local machine:
775
	Mapping process: make test
776
		Including column-based import: make test by_col=1
777
			If the row-based and column-based imports produce different inserted
778
			row counts, this usually means that a table is underconstrained
779
			(the unique indexes don't cover all possible rows).
780
			This can occur if you didn't use COALESCE(field, null_value) around
781
			a nullable field in a unique index. See sql_gen.null_sentinels for
782
			the appropriate null value to use.
783
	Map spreadsheet generation: make remake
784
	Missing mappings: make missing_mappings
785
	Everything (for most complete coverage): make test-all
786

    
787
Debugging:
788
	"Binary chop" debugging:
789
		(This is primarily useful for regressions that occurred in a previous
790
		revision, which was committed without running all the tests)
791
		up -r <rev>; make inputs/.TNRS/reinstall; make schemas/public/reinstall; make <failed-test>.xml
792
	.htaccess:
793
		mod_rewrite:
794
			**IMPORTANT**: whenever you change the DirectorySlash setting for a
795
				directory, you *must* clear your browser's cache to ensure that
796
				a cached redirect is not used. this is because RewriteRule
797
				redirects are (by default) temporary, but DirectorySlash
798
				redirects are permanent.
799
				for Firefox:
800
					press Cmd+Shift+Delete
801
					check only Cache
802
					press Enter or click Clear Now
803

    
804
WinMerge setup:
805
	In a Windows VM:
806
	Install WinMerge from <http://winmerge.org/>
807
	Open WinMerge
808
	Go to Edit > Options and click Compare in the left sidebar
809
	Enable "Moved block detection", as described at
810
		<http://manual.winmerge.org/Configuration.html#d0e5892>.
811
	Set Whitespace to Ignore change, as described at
812
		<http://manual.winmerge.org/Configuration.html#d0e5758>.
813

    
814
Documentation:
815
	To generate a Redmine-formatted list of steps for column-based import:
816
		On local machine:
817
		make schemas/public/reinstall
818
		make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
819
	To import and scrub just the test taxonomic names:
820
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
821
		inputs/test_taxonomic_names/test_scrub
822

    
823
General:
824
	To see a program's description, read its top-of-file comment
825
	To see a program's usage, run it without arguments
826
	To remake a directory: make <dir>/remake
827
	To remake a file: make <file>-remake
(6-6/11)