]> git.evergreen-ils.org Git - working/Evergreen.git/blob - docs/development/support_scripts.adoc
ad6d06a7aced6df16a82bce125a1be8486deb08d
[working/Evergreen.git] / docs / development / support_scripts.adoc
1 Support Scripts
2 ---------------
3
4 Various scripts are included with Evergreen in the `/openils/bin/` directory
5 (and in the source code in `Open-ILS/src/support-scripts` and
6 `Open-ILS/src/extras`). Some of them are used during
7 the installation process, such as `eg_db_config`, while others are usually
8 run as cron jobs for routine maintenance, such as `fine_generator.pl` and
9 `hold_targeter.pl`. Others are useful for less frequent needs, such as the
10 scripts for importing/exporting MARC records. You may explore these scripts
11 and adapt them for your local needs. You are also welcome to share your
12 improvements or ask any questions on the
13 http://evergreen-ils.org/communicate/[Evergreen IRC channel or email lists].
14
15 Here is a summary of the most commonly used scripts. The script name links
16 to more thorough documentation, if available.
17
18  * <<_processing_action_triggers,action_trigger_runner.pl>>
19    -- Useful for creating events for specified hooks and running pending events
20  * authority_authority_linker.pl
21    -- Links reference headings in authority records to main entry headings
22       in other authority records. Should be run at least once a day (only for
23           changed records).
24  * <<_authority_control_fields,authority_control_fields.pl>>
25    -- Links bibliographic records to the best matching authority record.
26       Should be run at least once a day (only for changed records).
27       You can accomplish this by running _authority_control_fields.pl --days-back=1_
28  * autogen.sh
29    -- Generates web files used by the OPAC, especially files related to
30       organization unit hierarchy, fieldmapper IDL, locales selection,
31       facet definitions, compressed JS files and related cache key
32  * clark-kent.pl
33    -- Used to start and stop the reporter (which runs scheduled reports)
34  * <<_creating_the_evergreen_database,eg_db_config>>
35    -- Creates database and schema, updates config files, sets Evergreen
36       administrator username and password
37  * fine_generator.pl
38  * hold_targeter.pl
39  * <<_importing_authority_records_from_command_line,marc2are.pl>>
40    -- Converts authority records from MARC format to Evergreen objects
41       suitable for importing via pg_loader.pl (or parallel_pg_loader.pl)
42  * marc2bre.pl
43    -- Converts bibliographic records from MARC format to Evergreen objects
44       suitable for importing via pg_loader.pl (or parallel_pg_loader.pl)
45  * marc2sre.pl
46    -- Converts serial records from MARC format to Evergreen objects
47       suitable for importing via pg_loader.pl (or parallel_pg_loader.pl)
48  * <<_marc_export,marc_export>>
49    -- Exports authority, bibliographic, and serial holdings records into
50       any of these formats: USMARC, UNIMARC, XML, BRE, ARE
51  * osrf_control
52    -- Used to start, stop and send signals to OpenSRF services
53  * parallel_pg_loader.pl
54    -- Uses the output of marc2bre.pl (or similar tools) to generate the SQL
55       for importing records into Evergreen in a parallel fashion
56
57 anchor:_authority_control_fields[]
58
59 authority_control_fields: Connecting Bibliographic and Authority records
60 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
62 indexterm:[authority control]
63
64 This script matches headings in bibliographic records to the appropriate
65 authority records. When it finds a match, it will add a subfield 0 to the 
66 matching bibliographic field.
67
68 Here is how the matching works:
69
70 [options="header",cols="1,1,3"]
71 |=========================================================
72 |Bibliographic field|Authority field it matches|Subfields that it examines
73
74 |100|100|a,b,c,d,f,g,j,k,l,n,p,q,t,u
75 |110|110|a,b,c,d,f,g,k,l,n,p,t,u
76 |111|111|a,c,d,e,f,g,j,k,l,n,p,q,t,u
77 |130|130|a,d,f,g,h,k,l,m,n,o,p,r,s,t
78 |600|100|a,b,c,d,f,g,h,j,k,l,m,n,o,p,q,r,s,t,v,x,y,z
79 |610|110|a,b,c,d,f,g,h,k,l,m,n,o,p,r,s,t,v,w,x,y,z
80 |611|111|a,c,d,e,f,g,h,j,k,l,n,p,q,s,t,v,x,y,z
81 |630|130|a,d,f,g,h,k,l,m,n,o,p,r,s,t,v,x,y,z
82 |648|148|a,v,x,y,z
83 |650|150|a,b,v,x,y,z
84 |651|151|a,v,x,y,z
85 |655|155|a,v,x,y,z
86 |700|100|a,b,c,d,f,g,j,k,l,n,p,q,t,u
87 |710|110|a,b,c,d,f,g,k,l,n,p,t,u
88 |711|111|a,c,d,e,f,g,j,k,l,n,p,q,t,u
89 |730|130|a,d,f,g,h,j,k,m,n,o,p,r,s,t
90 |751|151|a,v,x,y,z
91 |800|100|a,b,c,d,e,f,g,j,k,l,n,p,q,t,u,4
92 |830|130|a,d,f,g,h,k,l,m,n,o,p,r,s,t
93 |=========================================================
94
95
96 anchor:_marc_export[]
97
98 marc_export: Exporting Bibliographic Records into MARC files
99 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
101 indexterm:[marc_export]
102
103 The following procedure explains how to export Evergreen bibliographic
104 records into MARC files using the *marc_export* support script. All steps
105 should be performed by the `opensrf` user from your Evergreen server.
106
107 [NOTE]
108 Processing time for exporting records depends on several factors such as
109 the number of records you are exporting. It is recommended that you divide
110 the export ID files (records.txt) into a manageable number of records if
111 you are exporting a large number of records.
112
113  . Create a text file list of the Bibliographic record IDs you would like
114 to export from Evergreen. One way to do this is using SQL:
115 +
116 [source,sql]
117 ----
118 SELECT DISTINCT bre.id FROM biblio.record_entry AS bre
119     JOIN asset.call_number AS acn ON acn.record = bre.id 
120     WHERE bre.deleted='false' and owning_lib=101 \g /home/opensrf/records.txt;
121 ----
122 +
123 This query creates a file called `records.txt` containing a column of
124 distinct IDs of items owned by the organizational unit with the id 101.
125
126  . Navigate to the support-scripts folder
127 +
128 ----
129 cd /home/opensrf/Evergreen-ILS*/Open-ILS/src/support-scripts/
130 ----
131
132  . Run *marc_export*, using the ID file you created in step 1 to define which
133    files to export. The following example exports the records into MARCXML format.
134 +
135 ----
136 cat /home/opensrf/records.txt | ./marc_export --store -i -c /openils/conf/opensrf_core.xml \
137     -x /openils/conf/fm_IDL.xml -f XML --timeout 5 > exported_files.xml
138 ----
139
140 [NOTE]
141 ====================
142 `marc_export` does not output progress as it executes.
143 ====================
144
145 Options
146 ^^^^^^^
147
148 The *marc_export* support script includes several options.  You can find a complete list
149 by running `./marc_export -h`.  A few key options are also listed below:
150
151 --descendants and --library
152 +++++++++++++++++++++++++++
153
154 The `marc_export` script has two related options, `--descendants` and
155 `--library`.  Both options take one argument of an organizational unit
156
157 The `--library` option will export records with holdings at the specified
158 organizational unit only.  By default, this only includes physical holdings,
159 not electronic ones (also known as located URIs).
160
161 The `descendants` option works much like the `--library` option
162 except that it is aware of the org. tree and will export records with
163 holdings at the specified organizational unit and all of its descendants.
164 This is handy if you want to export the records for all of the branches
165 of a system.  You can do that by specifying this option and the system's
166 shortname, instead of specifying multiple `--library` options for each branch.
167
168 Both the `--library` and `--descendants` options can be repeated.
169 All of the specified org. units and their descendants will be included
170 in the output.  You can also combine `--library` and `--descendants`
171 options when necessary.
172
173 --since
174 +++++++
175
176 You can use the `--since` option to export records modified after a certain date and time.
177
178 --store
179 +++++++
180
181 By default, marc_export will use the reporter storage service, which should
182 work in most cases. But if you have a separate reporter database and you
183 know you want to talk directly to your main production database, then you
184 can set the `--store` option to `cstore` or `storage`. 
185
186 --uris
187 ++++++
188 The `--uris` option (short form: `-u`) allows you to  export records with
189 located URIs (i.e. electronic resources).  When used by itself, it will export
190 only records that have located URIs.  When used in conjunction with `--items`,
191 it will add records with located URIs but no items/copies to the output. 
192 If combined with a `--library` or `--descendants` option, this option will
193 limit its output to those records with URIs at the designated libraries.  The
194 best way to use this option is in combination with the `--items` and one of the
195 `--library` or `--descendants` options to export *all* of a library's
196 holdings both physical and electronic.
197
198
199 Importing Authority Records from Command Line
200 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
201
202 indexterm:[marc2are.pl]
203 indexterm:[pg_loader.pl]
204
205 The major advantages of the command line approach are its speed and its
206 convenience for system administrators who can perform bulk loads of
207 authority records in a controlled environment. For alternate instructions,
208 see the cataloging manual.
209
210  . Run *marc2are.pl* against the authority records, specifying the user
211 name, password, MARC type (USMARC or XML). Use `STDOUT` redirection to
212 either pipe the output directly into the next command or into an output
213 file for inspection. For example, to process a file with authority records
214 in MARCXML format named `auth_small.xml` using the default user name and
215 password, and directing the output into a file named `auth.are`:
216 +
217 ----
218 cd Open-ILS/src/extras/import/
219 perl marc2are.pl --user admin --pass open-ils --marctype XML auth_small.xml > auth.are
220 ----
221 +
222 [NOTE]
223 The MARC type will default to USMARC if the `--marctype` option is not specified.
224
225  . Run *parallel_pg_loader.pl* to generate the SQL necessary for importing the
226 authority records into your system. This script will create files in your
227 current directory with filenames like `pg_loader-output.are.sql` and
228 `pg_loader-output.sql` (which runs the previous SQL file). To continue with the
229 previous example by processing our new `auth.are` file:
230 +
231 ----
232 cd Open-ILS/src/extras/import/
233 perl parallel_pg_loader.pl --auto are --order are auth.are
234 ----
235 +
236 [TIP]
237 To save time for very large batches of records, you could simply pipe the
238 output of *marc2are.pl* directly into *parallel_pg_loader.pl*.
239
240  . Load the authority records from the SQL file that you generated in the
241 last step into your Evergreen database using the psql tool. Assuming the
242 default user name, host name, and database name for an Evergreen instance,
243 that command looks like:
244 +
245 ----
246 psql -U evergreen -h localhost -d evergreen -f pg_loader-output.sql
247 ----
248
249 Juvenile-to-adult batch script
250 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
251
252 The batch `juv_to_adult.srfsh` script is responsible for toggling a patron
253 from juvenile to adult. It should be set up as a cron job.
254
255 This script changes patrons to adult when they reach the age value set in the
256 library setting named "Juvenile Age Threshold" (`global.juvenile_age_threshold`).
257 When no library setting value is present at a given patron's home library, the
258 value passed in to the script will be used as a default.
259
260 MARC Stream Importer
261 ~~~~~~~~~~~~~~~~~~~~
262
263 The MARC Stream Importer can import authority records or bibliographic records.
264 A single running instance of the script can import either type of record, based
265 on the record leader.
266
267 This support script has its own configuration file, _marc_stream_importer.conf_, 
268 which includes settings related to logs, ports, uses, and access control.
269
270 The importer is even more flexible than the staff client import, including the
271 following options:
272
273  * _--bib-auto-overlay-exact_ and _--auth-auto-overlay-exact_: overlay/merge on
274 exact 901c matches
275  * _--bib-auto-overlay-1match_ and _--auth-auto-overlay-1match_: overlay/merge
276 when exactly one match is found
277  * _--bib-auto-overlay-best-match_ and _--auth-auto-overlay-best-match_:
278 overlay/merge on best match
279  * _--bib-import-no-match_ and _--auth-import-no-match_: import when no match
280 is found
281
282 One advantage to using this tool instead of the staff client Import interface
283 is that the MARC Stream Importer can load a group of files at once.
284