Project

General

Profile

1
Installation:
2
	Check out svn:
3
		sudo apt-get --yes install subversion # not preinstalled on Ubuntu
4
		svn co https://code.nceas.ucsb.edu/code/projects/bien/trunk bien
5
	cd bien/
6
	Install:
7
		**WARNING**: This will delete the public schema of your VegBIEN DB!
8
		make install
9
		# at "reload PATH" (if displayed), do what it says
10
		# at "[sudo] password for user", enter your password and press Enter
11
		# at "Modifying postgresql.conf and pg_hba.conf", type y and press Enter
12
		# at "kernel.shmmax [...] Press ENTER to continue":
13
			# open a new window
14
			# run what it says
15
			# press Ctrl-D
16
			# return to the previous window
17
			# press Enter
18
		# at "restart PostgreSQL manually ... Press ENTER to continue":
19
			# open a new window
20
			# run what it says
21
			# press Ctrl-D
22
			# return to the previous window
23
			# press Enter
24
		# at "This will delete the current public schema of your VegBIEN DB",
25
			type y and press Enter
26
	Uninstall: make uninstall
27
		**WARNING**: This will delete your entire VegBIEN DB!
28
		This includes all archived imports and staging tables.
29

    
30
Connecting to vegbiendev:
31
	ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
32
	cd /home/bien # should happen automatically at login
33

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

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

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

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

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

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

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

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

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

    
603
Datasource refreshing:
604
	VegBank:
605
		ssh -t vegbiendev.nceas.ucsb.edu exec sudo -u aaronmk -i
606
		make inputs/VegBank/vegbank.sql-remake
607
		make inputs/VegBank/reinstall quiet=1 &
608

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

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

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

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

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

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