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
		make install
10
		# at "reload PATH" (if displayed), do what it says
11
		# at "aaronmk@jupiter's password", enter the applicable password
12
		# at "Are you sure you want to continue connecting", type "yes" and
13
			press Enter
14
		# at "[sudo] password for user", enter your password and press Enter
15
		# at "Modifying postgresql.conf and pg_hba.conf", type y and press Enter
16
		# at "kernel.shmmax [...] Press ENTER to continue":
17
			# open a new window
18
			# run what it says
19
			# press Ctrl-D
20
			# return to the previous window
21
			# press Enter
22
		# at "restart PostgreSQL manually ... Press ENTER to continue":
23
			# open a new window
24
			# run what it says
25
			# press Ctrl-D
26
			# return to the previous window
27
			# press Enter
28
		# at "This will delete the current public schema of your VegBIEN DB",
29
			type y and press Enter
30
	Uninstall: make uninstall
31
		**WARNING**: This will delete your entire VegBIEN DB!
32
		This includes all archived imports and staging tables.
33

    
34
Connecting to vegbiendev:
35
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
36
	cd /home/bien # should happen automatically at login
37

    
38
Single datasource refresh:
39
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
40
	# -> Maintenance > to back up the vegbiendev databases
41
	# place updated extract in inputs/ACAD/_src/
42
	# place extracted flat file(s) in the appropriate table subdirs 
43
	rm=1 inputs/<datasrc>/run # reload staging tables
44
	make inputs/<datasrc>/reimport_scrub by_col=1 &
45
		# this works whether or not datasource is already imported
46
	tail -150 inputs/<datasrc>/*/logs/public.log.sql # view progress
47
	# -> Full database import > To re-run geoscrubbing
48
	# -> Full database import > To remake analytical DB
49
	# -> Maintenance > to back up the vegbiendev databases
50

    
51
Notes on system stability:
52
	**WARNING**: when shutting down the VM, always first stop Postgres:
53
		sudo service postgresql stop
54
		this prevents the OS from SIGKILLing Postgres, which sometimes causes
55
		database corruption 
56

    
57
Notes on running programs:
58
	**WARNING**: always start with a clean shell, to avoid spurious bugs. the
59
		shell should not have changes to the env vars. (there have been bugs
60
		that went away after closing and reopening the terminal window.) note
61
		that running `exec bash` is not sufficient to *reset* the env vars.
62

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

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

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

    
412
Maintenance:
413
	on a live machine, you should put the following in your .profile:
414
--
415
# make svn files web-accessible. this does not affect unversioned files, because
416
# these get the right permissions on the local machine instead.
417
umask ug=rwx,o=rx
418

    
419
unset TMOUT # TMOUT causes screen to exit even with background processes
420
--
421
	if http://vegbiendev.nceas.ucsb.edu/phppgadmin/ goes down:
422
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
423
			make phppgadmin-Linux
424
	regularly, re-run full-database import so that bugs in it don't pile up.
425
		it needs to be kept in working order so that it works when it's needed.
426
	to back up the vegbiendev databases:
427
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
428
		back up MySQL: # usually few changes, so do this first
429
			backups/mysql_snapshot
430
			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
431
			on local machine:
432
			l=1 swap=1 overwrite=1 inplace=1 local_dir=~ sync_remote_subdir=                          subpath=~/Documents/BIEN/var/lib/mysql.bak/                          bin/sync_upload
433
		back up Postgres:
434
			backups/pg_snapshot
435
	to synchronize vegbiendev, jupiter, and your local machine:
436
		**WARNING**: pay careful attention to all files that will be deleted or
437
			overwritten!
438
		install put if needed:
439
			download https://uutils.googlecode.com/svn/trunk/bin/put to ~/bin/ and `chmod +x` it
440
		when changes are made on vegbiendev:
441
			avoid extraneous diffs when rsyncing:
442
				on local machine:
443
					up; ./fix_perms
444
				ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
445
					up; ./fix_perms
446
				ssh aaronmk@jupiter.nceas.ucsb.edu
447
					up; ./fix_perms
448
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
449
				upload:
450
				overwrite=1 bin/sync_upload --size-only
451
					then review diff, and rerun with `l=1` prepended
452
			on your machine:
453
				download:
454
				overwrite=1 swap=1 src=. dest='aaronmk@jupiter.nceas.ucsb.edu:~/bien' put --exclude=.svn web/BIEN3/TWiki
455
					then review diff, and rerun with `l=1` prepended
456
				swap=1 bin/sync_upload backups/TNRS.backup
457
					then review diff, and rerun with `l=1` prepended
458
				overwrite=1 swap=1 bin/sync_upload --size-only
459
					then review diff, and rerun with `l=1` prepended
460
				overwrite=1 sync_remote_url=~/Dropbox/svn/ bin/sync_upload --existing --size-only # just update mtimes/perms
461
					then review diff, and rerun with `l=1` prepended
462
	to back up e-mails:
463
		on local machine:
464
		/Applications/gmvault-v1.8.1-beta/bin/gmvault sync --multiple-db-owner --type quick aaronmk.nceas@gmail.com
465
		open Thunderbird
466
		click the All Mail folder for each account and wait for it to download the e-mails in it
467
	to back up the version history:
468
		# back up first on the local machine, because often only the svnsync
469
			command gets run, and that way it will get backed up immediately to
470
			Dropbox (and hourly to Time Machine), while vegbiendev only gets
471
			backed up daily to tape
472
		on local machine:
473
		svnsync sync file://"$HOME"/Dropbox/docs/BIEN/svn_repo/ # initial runtime: 1.5 h ("08:21:38" - "06:45:26") @vegbiendev
474
		(cd ~/Dropbox/docs/BIEN/git/; git svn fetch)
475
		# use absolute path for vegbiendev commands because the Ubuntu 14.04
476
			version of rsync doesn't expand ~ properly
477
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:/data/dev/aaronmk/' put Dropbox/docs/BIEN/svn_repo/ # runtime: 1 min ("1:05.08")
478
			then review diff, and rerun with `l=1` prepended
479
		overwrite=1        src=~ dest='aaronmk@jupiter.nceas.ucsb.edu:/data/dev/aaronmk/' put Dropbox/docs/BIEN/git/
480
			then review diff, and rerun with `l=1` prepended
481
	to back up vegbiendev:
482
		do steps under Maintenance > "to synchronize vegbiendev, jupiter, and
483
			your local machine"
484
		on local machine:
485
			l=1 overwrite=1 inplace=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
486
			# enable --link-dest to work:
487
				chmod -R o+r ~/bien/.svn/; find ~/bien/.svn -type d -exec chmod o+rx {} \; # match perms
488
				l=1 overwrite=1 del= src='aaronmk@vegbiendev.nceas.ucsb.edu:~/bien/' dest=~/bien/ put --existing --size-only .svn/pristine/ # match times and perms
489
			l=1 overwrite=1 inplace=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/
490
				# --no-owner --no-group: needed to allow --link-dest to work
491
				# --link-dest: relative to dest, not currdir, so need abs path
492
	to back up the local machine's settings:
493
		do step when changes are made on vegbiendev > on your machine, download
494
		ssh aaronmk@jupiter.nceas.ucsb.edu
495
			(cd ~/Dropbox/svn/; up)
496
		on your machine:
497
			sudo find / -name .DS_Store -print -delete
498
			rm ~/'Library/Thunderbird/Profiles/9oo8rcyn.default/ImapMail/imap.googlemail.com/[Gmail].sbd/Spam'
499
				# remove the downloaded Spam folder, because spam e-mails often contain viruses that would trigger clamscan
500
			overwrite=1           sync_local_dir=~/Dropbox/svn/ sync_remote_subdir=Dropbox/svn/ bin/sync_upload --size-only # just update mtimes
501
				then review diff, and rerun with `l=1` prepended
502
			overwrite=1 inplace=1 sync_local_dir=~/             sync_remote_subdir=             bin/sync_upload ~/"VirtualBox VMs/**" # need inplace=1 because they are very large files
503
				then review diff, and rerun with `l=1` prepended
504
			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/"
505
				# sudo -E: needed for Documents/BIEN/vegbiendev*/
506
				then review diff, and rerun with `l=1` prepended
507
			pause Dropbox: system tray > Dropbox icon > gear icon > Pause Syncing
508
				this prevents Dropbox from trying to capture filesystem
509
				events while syncing
510
			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"
511
				then review diff, and rerun with `l=1` prepended
512
			resume Dropbox: system tray > Dropbox icon > gear icon > Resume Syncing
513
	to backup files not in Time Machine:
514
		**IMPORTANT**: need to use 2 TB external hard drive instead of Time
515
			Machine drive because Time Machine drive does not have
516
			~/Documents/BIEN/ in a location where it can be hardlinked against
517
		On local machine:
518
		on first run, create parent dirs:
519
			sudo mkdir -p '/Volumes/BIEN3.**SAVE**/Users/aaronmk/Documents/BIEN/'
520
			sudo mkdir -p '/Volumes/BIEN3.**SAVE**/usr/local/var/postgres/'
521
			l=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --existing
522
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --include='/vegbiendev**' --exclude='**' Users/aaronmk/Documents/BIEN/
523
			# this cannot be backed up by Time Machine because it dereferences hard links:
524
			#  `sudo find /Volumes/Time\ Machine\ Backups/Backups.backupdb/ ! -type d -links +1`
525
			#  returns no files when there is a single timestamped backup, but
526
			#  `sudo find / ! -type d -links +1` does
527
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put usr/local/var/postgres/
528
			# this cannot be backed up by Time Machine because it prevents the backup process from ending
529
		launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist # stop the PostgreSQL server
530
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put usr/local/var/postgres/
531
		launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist # start the PostgreSQL server
532
	to back up the local machine's hard drive:
533
		turn on and connect the 2 TB external hard drive
534
		screen
535
		# --exclude='/\**': exclude *-files indicating the (differing) retention
536
		#  statuses of the partitions involved
537
		pause Dropbox: system tray > Dropbox icon > gear icon > Pause Syncing
538
			otherwise, the backup of ~/.dropbox will be corrupted
539
		launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist # stop the PostgreSQL server
540
		l=1 overwrite=1 src=/ dest='/Volumes/BIEN3.**SAVE**/' sudo -E put --exclude='/\**' --exclude=/.fseventsd/ --exclude=/private/var/vm/
541
			# no --extended-attributes: rsync has to visit every file for this
542
			# runtime: 10 min (~600); initial runtime: 4-13 h ("2422.84"+"12379.91" .. "45813.19"+"747.96")
543
		launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist # start the PostgreSQL server
544
		resume Dropbox: system tray > Dropbox icon > gear icon > Resume Syncing
545
	to restore from Time Machine:
546
		# restart holding Alt
547
		# select Time Machine Backups
548
		# restore the last Time Machine backup to Macintosh HD
549
		# restart holding Alt
550
		# select Macintosh HD
551
		$ screen
552
		$ l=1 swap=1 src=/ dest=/Volumes/Time\ Machine\ Backups/ sudo -E put usr/local/var/postgres/ # runtime: 1 h ("4020.61")
553
		$ make postgres_restart
554
	VegCore data dictionary:
555
		Regularly, or whenever the VegCore data dictionary page
556
			(https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCore)
557
			is changed, regenerate mappings/VegCore.csv:
558
			On local machine:
559
			make mappings/VegCore.htm-remake; make mappings/
560
			apply new data dict mappings to datasource mappings/staging tables:
561
				inputs/run postprocess # runtime: see inputs/run
562
				time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
563
			svn di mappings/VegCore.tables.redmine
564
			If there are changes, update the data dictionary's Tables section
565
			When moving terms, check that no terms were lost: svn di
566
			svn ci -m 'mappings/VegCore.htm: regenerated from wiki'
567
			ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
568
				perform the steps under "apply new data dict mappings to
569
					datasource mappings/staging tables" above
570
	Important: Whenever you install a system update that affects PostgreSQL or
571
		any of its dependencies, such as libc, you should restart the PostgreSQL
572
		server. Otherwise, you may get strange errors like "the database system
573
		is in recovery mode" which go away upon reimport, or you may not be able
574
		to access the database as the postgres superuser. This applies to both
575
		Linux and Mac OS X.
576

    
577
Backups:
578
	Archived imports:
579
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
580
		Back up: make backups/<version>.backup &
581
			Note: To back up the last import, you must archive it first:
582
				make schemas/rotate
583
		Test: make -s backups/<version>.backup/test &
584
		Restore: make backups/<version>.backup/restore &
585
		Remove: make backups/<version>.backup/remove
586
		Download: make backups/<version>.backup/download
587
	TNRS cache:
588
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
589
		Back up: make backups/TNRS.backup-remake &
590
			runtime: 3 min ("real 2m48.859s")
591
		Restore:
592
			yes|make inputs/.TNRS/uninstall
593
			make backups/TNRS.backup/restore &
594
				runtime: 5.5 min ("real 5m35.829s")
595
			yes|make schemas/public/reinstall
596
				Must come after TNRS restore to recreate tnrs_input_name view
597
	Full DB:
598
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
599
		Back up: make backups/vegbien.<version>.backup &
600
		Test: make -s backups/vegbien.<version>.backup/test &
601
		Restore: make backups/vegbien.<version>.backup/restore &
602
		Download: make backups/vegbien.<version>.backup/download
603
	Import logs:
604
		On local machine:
605
		Download: make inputs/download-logs live=1
606

    
607
Datasource refreshing:
608
	VegBank:
609
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
610
		make inputs/VegBank/vegbank.sql-remake
611
		make inputs/VegBank/reinstall quiet=1 &
612

    
613
Schema changes:
614
	On local machine:
615
	When changing the analytical views, run sync_analytical_..._to_view()
616
		to update the corresponding table
617
	Remember to update the following files with any renamings:
618
		schemas/filter_ERD.csv
619
		mappings/VegCore-VegBIEN.csv
620
		mappings/verify.*.sql
621
	Regenerate schema from installed DB: make schemas/remake
622
	Reinstall DB from schema: make schemas/public/reinstall schemas/reinstall
623
		**WARNING**: This will delete the public schema of your VegBIEN DB!
624
	If needed, reinstall staging tables:
625
		On local machine:
626
			sudo -E -u postgres psql <<<'ALTER DATABASE vegbien RENAME TO vegbien_prev'
627
			make db
628
			. bin/reinstall_all
629
			Fix any bugs and retry until no errors
630
			make schemas/public/install
631
				This must be run *after* the datasources are installed, because
632
				views in public depend on some of the datasources
633
			sudo -E -u postgres psql <<<'DROP DATABASE vegbien_prev'
634
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
635
			repeat the above steps
636
			**WARNING**: Do not run this until reinstall_all runs successfully
637
			on the local machine, or the live DB may be unrestorable!
638
	update mappings and staging table column names:
639
		on local machine:
640
			inputs/run postprocess # runtime: see inputs/run
641
			time yes|make inputs/{NVS,SALVIAS,TEAM}/test # old-style import; runtime: 1 min ("0m59.692s") @starscream
642
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
643
			manually apply schema changes to the live public schema
644
			do steps under "on local machine" above
645
	Sync ERD with vegbien.sql schema:
646
		Run make schemas/vegbien.my.sql
647
		Open schemas/vegbien.ERD.mwb in MySQLWorkbench
648
		Go to File > Export > Synchronize With SQL CREATE Script...
649
		For Input File, select schemas/vegbien.my.sql
650
		Click Continue
651
		In the changes list, select each table with an arrow next to it
652
		Click Update Model
653
		Click Continue
654
		Note: The generated SQL script will be empty because we are syncing in
655
			the opposite direction
656
		Click Execute
657
		Reposition any lines that have been reset
658
		Add any new tables by dragging them from the Catalog in the left sidebar
659
			to the diagram
660
		Remove any deleted tables by right-clicking the table's diagram element,
661
			selecting Delete '<table name>', and clicking Delete
662
		Save
663
		If desired, update the graphical ERD exports (see below)
664
	Update graphical ERD exports:
665
		Go to File > Export > Export as PNG...
666
		Select schemas/vegbien.ERD.png and click Save
667
		Go to File > Export > Export as SVG...
668
		Select schemas/vegbien.ERD.svg and click Save
669
		Go to File > Export > Export as Single Page PDF...
670
		Select schemas/vegbien.ERD.1_pg.pdf and click Save
671
		Go to File > Print...
672
		In the lower left corner, click PDF > Save as PDF...
673
		Set the Title and Author to ""
674
		Select schemas/vegbien.ERD.pdf and click Save
675
		Commit: svn ci -m "schemas/vegbien.ERD.mwb: Regenerated exports"
676
	Refactoring tips:
677
		To rename a table:
678
			In vegbien.sql, do the following:
679
				Replace regexp (?<=_|\b)<old>(?=_|\b) with <new>
680
					This is necessary because the table name is *everywhere*
681
				Search for <new>
682
				Manually change back any replacements inside comments
683
		To rename a column:
684
			Rename the column: ALTER TABLE <table> RENAME <old> TO <new>;
685
			Recreate any foreign key for the column, removing CONSTRAINT <name>
686
				This resets the foreign key name using the new column name
687
	Creating a poster of the ERD:
688
		Determine the poster size:
689
			Measure the line height (from the bottom of one line to the bottom
690
				of another): 16.3cm/24 lines = 0.679cm
691
			Measure the height of the ERD: 35.4cm*2 = 70.8cm
692
			Zoom in as far as possible
693
			Measure the height of a capital letter: 3.5mm
694
			Measure the line height: 8.5mm
695
			Calculate the text's fraction of the line height: 3.5mm/8.5mm = 0.41
696
			Calculate the text height: 0.679cm*0.41 = 0.28cm
697
			Calculate the text height's fraction of the ERD height:
698
				0.28cm/70.8cm = 0.0040
699
			Measure the text height on the *VegBank* ERD poster: 5.5mm = 0.55cm
700
			Calculate the VegBIEN poster height to make the text the same size:
701
				0.55cm/0.0040 = 137.5cm H; *1in/2.54cm = 54.1in H
702
			The ERD aspect ratio is 11 in W x (2*8.5in H) = 11x17 portrait
703
			Calculate the VegBIEN poster width: 54.1in H*11W/17H = 35.0in W
704
			The minimum VegBIEN poster size is 35x54in portrait
705
		Determine the cost:
706
			The FedEx Kinkos near NCEAS (1030 State St, Santa Barbara, CA 93101)
707
				charges the following for posters:
708
				base: $7.25/sq ft
709
				lamination: $3/sq ft
710
				mounting on a board: $8/sq ft
711

    
712
Testing:
713
	On a development machine, you should put the following in your .profile:
714
		umask ug=rwx,o= # prevent files from becoming web-accessible
715
		export log= n=2
716
	For development machine specs, see /planning/resources/dev_machine.specs/
717
	On local machine:
718
	Mapping process: make test
719
		Including column-based import: make test by_col=1
720
			If the row-based and column-based imports produce different inserted
721
			row counts, this usually means that a table is underconstrained
722
			(the unique indexes don't cover all possible rows).
723
			This can occur if you didn't use COALESCE(field, null_value) around
724
			a nullable field in a unique index. See sql_gen.null_sentinels for
725
			the appropriate null value to use.
726
	Map spreadsheet generation: make remake
727
	Missing mappings: make missing_mappings
728
	Everything (for most complete coverage): make test-all
729

    
730
Debugging:
731
	"Binary chop" debugging:
732
		(This is primarily useful for regressions that occurred in a previous
733
		revision, which was committed without running all the tests)
734
		up -r <rev>; make inputs/.TNRS/reinstall; make schemas/public/reinstall; make <failed-test>.xml
735
	.htaccess:
736
		mod_rewrite:
737
			**IMPORTANT**: whenever you change the DirectorySlash setting for a
738
				directory, you *must* clear your browser's cache to ensure that
739
				a cached redirect is not used. this is because RewriteRule
740
				redirects are (by default) temporary, but DirectorySlash
741
				redirects are permanent.
742
				for Firefox:
743
					press Cmd+Shift+Delete
744
					check only Cache
745
					press Enter or click Clear Now
746

    
747
WinMerge setup:
748
	In a Windows VM:
749
	Install WinMerge from <http://winmerge.org/>
750
	Open WinMerge
751
	Go to Edit > Options and click Compare in the left sidebar
752
	Enable "Moved block detection", as described at
753
		<http://manual.winmerge.org/Configuration.html#d0e5892>.
754
	Set Whitespace to Ignore change, as described at
755
		<http://manual.winmerge.org/Configuration.html#d0e5758>.
756

    
757
Documentation:
758
	To generate a Redmine-formatted list of steps for column-based import:
759
		On local machine:
760
		make schemas/public/reinstall
761
		make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
762
	To import and scrub just the test taxonomic names:
763
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
764
		inputs/test_taxonomic_names/test_scrub
765

    
766
General:
767
	To see a program's description, read its top-of-file comment
768
	To see a program's usage, run it without arguments
769
	To remake a directory: make <dir>/remake
770
	To remake a file: make <file>-remake
(6-6/11)