]> git.evergreen-ils.org Git - working/Evergreen.git/blob - 1.6/admin/migratingdata_1.6.xml
Remove reference to program_name and program_code since this is org specific and...
[working/Evergreen.git] / 1.6 / admin / migratingdata_1.6.xml
1 <?xml version='1.0' encoding='UTF-8'?>\r
2 <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude"\r
3             xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:id="migratingdata" >\r
4         <info>          \r
5         <title>Migrating Data</title>\r
6                 <abstract>\r
7                         <para>Migrating data into Evergreen can be one of the most daunting tasks for an administrator. This chapter will explain some procedures to help to migrate \r
8                         bibliographic records, copies and patrons into the Evergreen system. This chapter requires advanced ILS Administration experience, knowledge of Evergreen data structures, \r
9                         as well as knowledge of how to export data from your current system or access to data export files from your current system.</para>\r
10                 </abstract>\r
11         </info>    \r
12         <section xml:id="migratingbibrecords">\r
13                 <title>Migrating Bibliographic Records</title>\r
14                 <indexterm><primary>migrating</primary><secondary>importing bibliographic records</secondary></indexterm>\r
15                 <para>\r
16                 One of the most important and challenging  tasks is migrating your bibliographic records to a new system. The procedure may be different depending on the system from which you \r
17                 are migrating  and the content of the marc records exported from the existing system. The procedures in this section deal with the process once the data from the existing system \r
18                 is exported into marc records. It does not cover exporting data from your existing non-Evergreen system.</para>\r
19                 <para>Several tools for importing bibliographic records into Evergreen can be found in the Evergreen installation folder \r
20                 (<filename class="directory">/home/opensrf/Evergreen-ILS-1.6.1.6/Open-ILS/src/extras/import/</filename> ) and are also available from the Evergreen repository \r
21                 (<link xl:href="http://svn.open-ils.org/trac/ILS/browser/branches/rel_1_6_1/Open-ILS/src/extras/import" xl:title="import scripts - Evergreen repository">\r
22                 http://svn.open-ils.org/trac/ILS/browser/branches/rel_1_6_1/Open-ILS/src/extras/import</link>).</para> \r
23                 <simplesect>\r
24                         <title>Converting MARC records to Evergreen BRE JSON format</title>\r
25                         <indexterm><primary>BRE JSON</primary></indexterm>\r
26                         <para>If you are starting with MARC records from your existing system or another source, use the marc2bre.pl script to create the JSON representation of a bibliographic \r
27                         record entry (hence bre) in Evergreen. <filename>marc2bre.pl</filename> can perform the following functions:</para>\r
28                         <itemizedlist> \r
29                                 <listitem><para>Converts <systemitem>MARC-8</systemitem> encoded records to <systemitem>UTF-8</systemitem> encoding</para></listitem>\r
30                                 <listitem><para>Converts <systemitem>MARC21</systemitem> to <systemitem>MARCXML21</systemitem></para></listitem>\r
31                                 <listitem><para>Select the unique record number field (common choices are '035' or '001'; check your records as you might be surprised how a supposedly unique field \r
32                                 actually has duplicates, though marc2bre.pl will select a unique identifier for subsequent duplicates)</para></listitem>\r
33                                 <listitem><para>Extracts certain pertinent fields indexing and display purposes (along with the complete MARCXML21 record)</para></listitem>\r
34                                 <listitem><para>Sets the ID number of the first record from this batch to be imported into the biblio.record_entry table (hint - run the following \r
35                                 <systemitem>SQL</systemitem> to determine what this number should be to avoid conflicts:</para>\r
36 <screen>\r
37 <userinput>psql -U postgres evergreen</userinput>\r
38 <userinput> # SELECT MAX(id)+1 FROM biblio.record_entry;</userinput>\r
39 </screen>\r
40                         </listitem>\r
41                         <listitem>\r
42                                 <para>If you are processing multiple sets of MARC records with <command>marc2bre.pl</command>before loading the records into the database, you will need to keep track \r
43                                 of the starting ID number for each subsequent batch of records that you are importing. For example, if you are processing three files of MARC records with 10000 \r
44                                 records each into a clean database, you would use <option>–startid 1</option>, <option>–startid 10001</option>, and <option>–startid 20001</option> \r
45                                 parameters for each respective file.</para>\r
46                         </listitem>\r
47                         <listitem>\r
48                                 <para>Ignore <quote>trash</quote> fields that you do not want to retain in Evergreen</para>\r
49                         </listitem>\r
50                         <listitem>\r
51                                 <para>If you use <filename>marc2bre.pl</filename> to convert your MARC records from the <systemitem>MARC-8</systemitem> encoding to the UTF-8 encoding, it relies\r
52                                  on the <systemitem>MARC::Charset Perl</systemitem> module to complete the conversion. When importing a large set of items, you can speed up the process by using a \r
53                                 utility like <systemitem>marc4j</systemitem> or <systemitem>marcdumper</systemitem> to convert the records \r
54                                 to <systemitem>MARC21XML</systemitem> and <systemitem>UTF-8</systemitem> before running them through <command>marc2bre.pl</command> with the \r
55                                 <option>–marctype=XML</option> flag to tell <command>marc2bre.pl</command> that the records are already in <systemitem>MARC21XML</systemitem> format with \r
56                                 the <systemitem>UTF-8 </systemitem>encoding. If you take this approach, due to a current limitation of <systemitem>MARC::File::XML</systemitem> you have to do a \r
57                                 horrible thing and ensure that there are no namespace prefixes in front of the element names. <filename>marc2bre.pl</filename> cannot parse the following \r
58                                 example:</para>\r
59 \r
60 <programlisting language="xml">\r
61 <![CDATA[\r
62 \r
63 <?xml version="1.0" encoding="UTF-8" ?>\r
64 <marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim" \r
65   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \r
66   xsi:schemaLocation="http://www.loc.gov/MARC/slim \r
67 http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">\r
68   <marc:record>\r
69     <marc:leader>00677nam a2200193 a 4500</marc:leader>\r
70     <marc:controlfield tag="001">H01-0000844</marc:controlfield>\r
71     <marc:controlfield tag="007">t </marc:controlfield>\r
72     <marc:controlfield tag="008">060420s1950    xx            000 u fre d</marc:controlfield>\r
73     <marc:datafield tag="040" ind1=" " ind2=" ">\r
74       <marc:subfield code="a">CaOHCU</marc:subfield>\r
75       <marc:subfield code="b">fre</marc:subfield>\r
76     </marc:datafield>\r
77 ...\r
78 ]]>;\r
79 </programlisting>\r
80                         \r
81                         <para>But marc2bre.pl can parse the same example with the namespace prefixes removed:</para>\r
82 <programlisting language="xml">\r
83 <![CDATA[\r
84 <?xml version="1.0" encoding="UTF-8" ?>\r
85 <collection xmlns:marc="http://www.loc.gov/MARC21/slim" \r
86   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \r
87   xsi:schemaLocation="http://www.loc.gov/MARC/slim \r
88 http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">\r
89   <record>\r
90     <leader>00677nam a2200193 a 4500</leader>\r
91     <controlfield tag="001">H01-0000844</controlfield>\r
92     <controlfield tag="007">t </controlfield>\r
93     <controlfield tag="008">060420s1950    xx            000 u fre d</controlfield>\r
94     <datafield tag="040" ind1=" " ind2=" ">\r
95       <subfield code="a">CaOHCU</subfield>\r
96       <subfield code="b">fre</subfield>\r
97     </datafield>\r
98 ...\r
99 ]]>;\r
100 </programlisting>\r
101                                 </listitem>\r
102                         </itemizedlist>\r
103                 </simplesect>\r
104                 <simplesect>\r
105                         <title>Converting Records for Import into PostgreSQL</title>\r
106                         <indexterm><primary>migrating</primary><secondary>import into PostgreSQL</secondary></indexterm>\r
107                         <para>Once you have your records in Evergreen's <systemitem>BRE JSON</systemitem> format, you then need to use <command>direct_ingest.pl</command> to convert the records \r
108                         into the generic ingest <systemitem>JSON</systemitem> format for Open-ILS. \r
109                         This step uses the <systemitem>open-ils.ingest</systemitem> application to extract the data that will be indexed in the database. </para>\r
110                         <para>Once you have your records in Open-ILS <systemitem>JSON</systemitem> ingest format, you then need to use <command>pg_loader.pl</command> to convert these records into a \r
111                         set of <systemitem>SQL</systemitem> statements that you can use to \r
112                         load the records into PostgreSQL. The <option>–order</option> and <option>–autoprimary</option> command line options (bre, mrd, mfr, etc) map to class IDs defined in \r
113                         <filename>/openils/conf/fm_IDL.xml</filename>.</para>\r
114                 </simplesect>           \r
115                 <simplesect>\r
116                         <title>Adding Metarecords to the Database</title>\r
117                         <indexterm><primary>migrating</primary><secondary>adding metarecords</secondary></indexterm>\r
118                         <para>One you have loaded the records into PostgreSQL, you can create metarecord entries in the <link linkend="metabib.table.metarecord">metabib.metarecord</link> table by                             running the following <systemitem>SQL</systemitem>:</para>\r
119 <screen>\r
120 <userinput>psql evergreen</userinput>\r
121 <userinput># \i /home/opensrf/Evergreen-ILS-1.6*/src/extras/import/quick_metarecord_map.sql</userinput>\r
122 </screen>\r
123                         <para>Metarecords are required to place holds on items, among other actions.</para>\r
124                 </simplesect>   \r
125         </section>\r
126 \r
127 \r
128 \r
129 <section xml:id="migrating_records_using_migration_tools">\r
130                 <title>Migrating Bibliographic Records Using the ESI Migration Tools</title>\r
131                 <indexterm><primary>migrating</primary><secondary>bibliograohic records</secondary></indexterm> \r
132                 <para>The following procedure explains how to migrate bibliographic records from marc records into Evergreen. This is a general guide and will need to be adjusted for your \r
133                 specific environment. It does not cover exporting records from specific proprietary ILS \r
134                 systems. For assistance with exporting records from your current system please refer to the manuals for your system or you might try to ask for help from the \r
135                 <link linkend="more_info">Evergreen community</link>.</para>\r
136                 \r
137                 <procedure>\r
138                         <step>\r
139                                 <para>Download the Evergreen <link xl:href="http://git.esilibrary.com/?p=migration-tools.git;a=summary" \r
140                                 xl:title="Equinox migration utilities">migration utilities</link> from the git repository.</para>\r
141                                 <para>Use the command <command>git clone git://git.esilibrary.com/git/migration-tools.git</command> to clone the migration tools.</para>\r
142                                  <para>Install the migration tools:</para>\r
143 <screen>\r
144 <userinput>\r
145 <![CDATA[\r
146 cd migration-tools/Equinox-Migration\r
147 perl Makefile.PL\r
148 make\r
149 make test\r
150 make install\r
151 ]]>\r
152 </userinput>\r
153 </screen>\r
154 </step> \r
155                         <step>\r
156                                 <para>Add environmental variables for migration and import tools. These paths must point to:\r
157                                         <itemizedlist>\r
158                                                 <listitem>the import perl scripts bundled with Evergreen </listitem>\r
159                                                 <listitem>the folder where you extracted the migration tools</listitem>\r
160                                                 <listitem>the location of the Equinox-Migration perl modules </listitem>\r
161                                                 <listitem>the location of the Evergreen perl modules (e.g. perl5)</listitem>\r
162                                         </itemizedlist>\r
163                                 </para> \r
164 <screen>\r
165 <userinput>\r
166 export PATH=[<emphasis class="italic">path to Evergreen</emphasis>]/Open-ILS/src/extras/import: \\r
167 /[<emphasis class="italic">path to migration-tools</emphasis>]/migration-tools:$PATH:.\r
168 export PERL5LIB=/openils/lib/perl5: \\r
169 /[<emphasis class="italic">path to migration-tools directory</emphasis>]/migration-tools/Equinox-Migration/lib\r
170 </userinput>\r
171 </screen>\r
172 </step>\r
173 <step>\r
174                                 <para>Dump marc records into MARCXML using <systemitem>yaz-marcdump</systemitem></para>\r
175 \r
176 <screen>\r
177 <userinput>\r
178 <![CDATA[\r
179 echo '<?xml version="1.0" encoding="UTF-8" ?>' > imported_marc_records.xml\r
180 yaz-marcdump -f MARC-8 -t UTF-8 -o marcxml imported_marc_records.mrc >> imported_marc_records.xml\r
181 ]]>\r
182 </userinput>\r
183 </screen>\r
184 </step> \r
185 <step>\r
186                                 <para>Test validity of XML file using <systemitem>xmllint</systemitem></para>\r
187 <screen>\r
188 \r
189 <userinput>\r
190 <![CDATA[\r
191  xmllint --noout imported_marc_records.xml 2> marc.xml.err\r
192 ]]>\r
193 </userinput>\r
194 </screen>\r
195 </step> \r
196 \r
197 <step>\r
198                                 <para>Clean up the marc xml file using the <systemitem>marc_cleanup</systemitem> utility:</para>\r
199 <screen>\r
200 <userinput>\r
201 marc_cleanup --marcfile=imported_marc_records.xml --fullauto [--renumber-from #] -ot 001\r
202 </userinput>    \r
203 </screen>\r
204                                 <para>The <option>--renumber-from</option> is required if you have bibliographic records already in your system. Use this to set the starting id number higher \r
205                                 then the last id in the biblio.record_entry table. The marc_cleanup command will generate a file called <filename>clean.marc.xml</filename></para>\r
206 </step>\r
207 <step>\r
208                                 <para>Create a fingerprinter file using the <systemitem>fingerprinter</systemitem> utility:</para>\r
209 <screen>\r
210 <userinput>\r
211 fingerprinter -o incumbent.fp -x incumbent.ex clean.marc.xml\r
212 </userinput>                    \r
213 </screen>\r
214                                 <para><systemitem>fingerprinter</systemitem> is used for deduplification of the incumbent records. The <option>-o</option> option specifies the \r
215                                 output file and the <option>-x</option> option is used to specify the error output file.</para>\r
216 </step>\r
217 <step>\r
218                                 <para>Create a fingerprinter file for existing Evergreen bibliographic records using the <systemitem>fingerprinter</systemitem> utility if you \r
219                                 have existing bibliographic records in your system previously imported:</para>\r
220 <screen>\r
221 <userinput>\r
222 fingerprinter -o production.fp -x production.fp.ex --marctype=MARC21 existing_marc_records.mrc \\r
223 --tag=901 --subfield=c\r
224 </userinput>\r
225 </screen>\r
226                                 <para><systemitem>fingerprinter</systemitem> is used for deduplification of the incumbant records.</para>\r
227 </step>\r
228 \r
229 <step>\r
230                                 <para>Create a merged fingerprint file removing duplicate records.</para>\r
231 <screen>\r
232 <userinput>\r
233 cat cat production.fp incumbent.fp | sort -r > dedupe.fp\r
234 match_fingerprints [-t start id] -o records.merge dedupe.fp\r
235 </userinput>\r
236 </screen>\r
237 </step>\r
238 \r
239 <step>\r
240                                 <para>Create a new import XML file using the <systemitem>extract_loadset</systemitem> utility</para>\r
241 <screen>\r
242 <userinput>extract_loadset -l 1 -i clean.marc.xml -o merged.xml records.merge</userinput>\r
243 </screen>\r
244 </step>\r
245 \r
246 <step>\r
247                                 <para>Extract all of the currently used TCN's an generate the .bre and .ingest files to prepare for the bibliographic record load.</para>\r
248 <screen>\r
249 <userinput>\r
250 psql -U evergreen -c "select tcn_value from biblio.record_entry where not deleted" \\r
251 | perl -npe 's/^\s+//;' > used_tcns\r
252 marc2bre.pl --idfield 903 [--startid=#] --marctype=XML -f final.xml \\r
253 --used_tcn_file=used_tcns > evergreen_bre_import_file.bre\r
254 </userinput>\r
255 </screen>\r
256                                 <note>\r
257                                         <para> The option <option>--startid</option> needs to match the start id used in earlier steps and must be higher than largest id value \r
258                                         in the biblio.record_entry table. the option <option>--idfield</option> should match the marc datafield used to store your records ids.</para>\r
259                                 </note>\r
260 </step>\r
261 \r
262 <step>\r
263                                 <para>Ingest the bibliographic records into the Evergreen database.</para>\r
264 <screen>\r
265 <userinput>\r
266 <![CDATA[\r
267 direct_ingest.pl < evergreen_bre_import_file.bre > evergreen_ingest_file.ingest\r
268 parallel_pg_loader.pl \\r
269 -or bre \\r
270 -or mrd \\r
271 -or mfr \\r
272 -or mtfe \\r
273 -or mafe \\r
274 -or msfe \\r
275 -or mkfe \\r
276 -or msefe \\r
277 -a mrd \\r
278 -a mfr \\r
279 -a mtfe \\r
280 -a mafe \\r
281 -a msfe \\r
282 -a mkfe \\r
283 -a msefe evergreen_ingest_file.ingest\r
284 ]]>\r
285 </userinput>\r
286 </screen>\r
287                         </step>\r
288                         <step>\r
289                                 <para>Load the records using psql and the sql scripts generated from the previous step.</para>\r
290 <screen>\r
291 <userinput>\r
292 <![CDATA[\r
293 psql -U evergreen < pg_loader-output.sql > load_pg_loader-output\r
294 psql -U evergreen < ~/Ever*/Open-ILS/src/extras/import/quick_metarecord_map.sql > log.create_metabib\r
295 ]]>\r
296 </userinput>\r
297 </screen>\r
298                         </step>\r
299                         <step>\r
300                                 <para>Extract holdings from marc records for importing copies into Evergreen using the <systemitem>extract_holdings</systemitem> utility.</para>\r
301 <screen>\r
302 <userinput>\r
303 extract_holdings --marcfile=clean.marc.xml --holding 999 --copyid 999i --map holdings.map\r
304 </userinput>\r
305 </screen>\r
306                                 <para>This command would extract holdings based on the 949 datafield in the marc records. The copy id is generated from the subfile i in the 999 datafield. You may \r
307                                 need to adjust these options based on the field used for holdings informatiom in your marc records.</para>\r
308                                 <para>The <option>map</option> option <filename>holdings.map</filename> refers to a file to be used for mapping subfields to the holdings data you would like extracted. Here is an example based on mapping holdings data to the 999 data field:</para>\r
309 <programlisting>\r
310 <![CDATA[\r
311 callnum 999 a\r
312 barcode 999 i\r
313 location 999 l\r
314 owning_lib 999 m\r
315 circ_modifier 999 t\r
316 ]]>\r
317 </programlisting>\r
318                                 <para>Running the extract holdings script should produce an sql script <filename>HOLDINGS.pg</filename> similar to:</para>\r
319 <programlisting language="sql">\r
320 BEGIN;\r
321 \r
322 egid, hseq, l_callnum, l_barcode, l_location, l_owning_lib, l_circ_modifier,\r
323 40      0       HD3616.K853 U54 1997    30731100751928  STACKS  FENNELL BOOK\r
324 41      1       HV6548.C3 S984 1998     30731100826613  STACKS  FENNELL BOOK\r
325 41      2       HV6548.C3 S984 1998     30731100804958  STACKS  BRANTFORD       BOOK\r
326 ...\r
327 </programlisting>\r
328   \r
329                                 <para>Edit the holdings.pg sql script like so:</para> \r
330 <programlisting language="sql">\r
331 BEGIN;\r
332 \r
333 <emphasis class="bold">TRUNCATE TABLE staging_items;</emphasis>\r
334 \r
335 <emphasis class="bold">INSERT INTO staging_items (</emphasis>egid, hseq, l_callnum, l_barcode, \r
336 l_location, l_owning_lib, l_circ_modifier<emphasis>) FROM stdin;</emphasis> \r
337 40      0       HD3616.K853 U54 1997    30731100751928  STACKS  FENNELL BOOK\r
338 41      1       HV6548.C3 S984 1998     30731100826613  STACKS  FENNELL BOOK\r
339 41      2       HV6548.C3 S984 1998     30731100804958  STACKS  BRANTFORD       BOOK\r
340 <emphasis>\.\r
341 \r
342 COMMIT;</emphasis>\r
343 </programlisting>\r
344                         <para>This file can be used for importing holdings into Evergreen. the <database class="field">egid</database> is a critical column. It is used to link the volume and \r
345                                 copy to the bibliographic record. Please refer to <link linkend="migratingbibrecordcopies">for the steps to import your holdings into Evergreen.</link></para> \r
346                         </step>\r
347                 </procedure>\r
348                 \r
349         </section>\r
350         <section xml:id="migratingbibrecordcopies">\r
351                 <title>Adding Copies to Bibliographic Records</title><indexterm><primary>migrating</primary><secondary>holdings</secondary></indexterm> \r
352                 <para>Before bibliographic records can be found in an OPAC search copies will need to be created.  It is very important to understand how various tables related to each other in regards \r
353                 to holdings maintenance.</para> \r
354                 <para>The following procedure will guide you through the process of populating Evergreen with volumes and copies. This is a very simple example. The SQL queries may need to be adjusted \r
355                 for the specific data in your holdings.</para>  \r
356                 <procedure>\r
357                         <step>\r
358                                 <para>Create a staging_items staging table to hold the holdings data:</para>\r
359 <programlisting language="sql">\r
360 CREATE TABLE staging_items (\r
361         l_callnum text, -- call number label\r
362         hseq int, \r
363         egid  int,  -- biblio.record_entry_id\r
364         createdate      date,\r
365         l_location        text,\r
366         l_barcode         text,\r
367         l_circ_modifier       text,\r
368         l_owning_lib      text -- actor.org_unit.shortname \r
369 );\r
370 </programlisting>\r
371                         </step> \r
372                         <step>\r
373                                 <para>Import the items using the HOLDINGS.pg SQL script created using the extract_holdings utility.</para>\r
374 <screen>\r
375 <userinput>psql -U evergreen -f HOLDINGS.pg evergreen</userinput>\r
376 </screen>\r
377                                 <para>the file <filename>HOLDINGS.pg</filename> and/or the COPY query may need to be adjusted for your particular circumstances.</para>  \r
378                         </step>\r
379                         \r
380 \r
381                         <step>\r
382                                 <para>Generate shelving locations from your staging table.</para>\r
383 <programlisting language="sql">\r
384 INSERT INTO asset.copy_location (name, owning_lib)\r
385 SELECT  DISTINCT l.l_location, ou.id\r
386 FROM  staging_items l \r
387        JOIN actor.org_unit ou   ON (l.l_owning_lib = ou.shortname); \r
388 </programlisting>\r
389                         </step>\r
390                         <step>\r
391                                 <para>Generate circulation modifiers from your staging table.</para>\r
392 <programlisting language="sql">\r
393 INSERT INTO config.circ_modifier (code, name, description, sip2_media_type, magnetic_media)\r
394         SELECT  DISTINCT l_circ_modifier AS code,\r
395           l_circ_modifier AS name,\r
396           LOWER(l_circ_modifier) AS description,\r
397           '001' AS sip2_media_type,\r
398           FALSE AS magnetic_media\r
399           FROM  staging_items\r
400           WHERE l_circ_modifier NOT IN (SELECT code FROM config.circ_modifier);\r
401 </programlisting>\r
402                         </step>\r
403                         <step>\r
404                                 <para>Generate call numbers from your staging table:</para>\r
405 <programlisting language="sql">\r
406 INSERT INTO asset.call_number (creator,editor,record,label,owning_lib)\r
407   SELECT  DISTINCT 1, 1, l.egid, l.l_callnum, ou.id\r
408   FROM  staging_items l\r
409   JOIN actor.org_unit ou ON (l.l_owning_lib = ou.shortname);\r
410 </programlisting>\r
411                         </step>\r
412                         <step>\r
413                                 <para>Generate copies from your staging table:</para>\r
414 <programlisting language="sql">\r
415 INSERT INTO asset.copy (\r
416 circ_lib, creator, editor, create_date, barcode,\r
417 STATUS, location, loan_duration, fine_level, circ_modifier, deposit, ref, call_number)          \r
418 \r
419 SELECT  DISTINCT ou.id AS circ_lib,\r
420         1 AS creator,\r
421         1 AS editor,\r
422         l.l_createdate AS create_date,\r
423         l.l_barcode AS barcode,\r
424         0 AS STATUS,\r
425         cl.id AS location,\r
426         2 AS loan_duration,\r
427         2 AS fine_level,\r
428         l.l_circ_modifier AS circ_modifier,\r
429         FALSE AS deposit,\r
430         CASE\r
431         WHEN l.l_circ_modifier = 'REFERENCE' THEN TRUE\r
432         ELSE FALSE\r
433         END AS ref,                                             \r
434         cn.id AS call_number\r
435         FROM  staging_items l\r
436                 JOIN actor.org_unit ou\r
437                         ON (l.l_owning_lib = ou.shortname)\r
438                 JOIN asset.copy_location cl\r
439                         ON (ou.id = cl.owning_lib AND l.l_location = cl.name)\r
440                 JOIN metabib.real_full_rec m \r
441                         ON (m.record = l.egid)\r
442                 JOIN asset.call_number cn\r
443                         ON (ou.id = cn.owning_lib  \r
444                         AND m.record = cn.record       \r
445                         AND l.l_callnum = cn.label)      \r
446 </programlisting>\r
447                                 <para>You should now have copies in your Evergreen database and should be able to search and find the bibliographic records with attached copies.</para> \r
448                         </step>\r
449                 </procedure>\r
450         </section>\r
451         <section xml:id="migratingpatrons">\r
452                 <title>Migrating Patron Data</title>\r
453                 <indexterm><primary>migrating</primary><secondary>patrons</secondary></indexterm>\r
454                 <para>\r
455                 This section will explain the task of migrating your patron data from comma delimited files<indexterm><primary>comma delimited files</primary></indexterm> into Evergreen. \r
456                 It does not deal with the process of exporting from the non-Evergreen \r
457                 system since this process may vary depending on where you are extracting your patron records. Patron could come from an ILS or it could come from a student database in the case of \r
458                 academic records.               \r
459                 </para>\r
460                 <para>When importing records into Evergreen you will need to populate 3 tables in your Evergreen database:</para>\r
461                 <itemizedlist>\r
462                         <listitem><link linkend="actor.table.usr">actor.usr</link> - The main table for user data</listitem>\r
463                         <listitem><link linkend="actor.table.card">actor.card</link> - Stores the barcode for users; Users can have more than 1 card but only 1 can be active at a given time;</listitem>\r
464                         <listitem><link linkend="actor.table.usr-address">actor.usr_address</link> - Used for storing address information; A user can have more than one address.</listitem>\r
465                 </itemizedlist>\r
466                 <para>Before following the procedures below to import patron data into Evergreen, it is a good idea to examine the fields in these tables in order to decide on a strategy \r
467                 for data to include \r
468                 in your import. It is important to understand the data types and constraints on each field.</para>\r
469                 <procedure>\r
470                         <step>\r
471                                 <para>Export the patron data from your existing ILS or from another source into a comma delimited file. The comma delimited file used for importing\r
472                                  the records should use Unicode (UTF8) <indexterm><primary>Unicode</primary></indexterm> character encoding.</para>\r
473                         </step>\r
474                         <step>\r
475                                 <para>Create a staging table.<indexterm><primary>staging table</primary></indexterm>  A staging table will allow you to tweak the data before importing. \r
476                                 Here is an example sql statement:</para>\r
477                                 <indexterm><primary>sql</primary></indexterm> \r
478 <programlisting language="sql">\r
479 CREATE TABLE students (\r
480          student_id int, barcode text, last_name text, first_name text, email text, address_type text, street1 text, street2 text, \r
481         city text, province text, country text, postal_code text, phone text, profile int, \r
482         ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, \r
483         net_access_level int DEFAULT 2, password text\r
484 ); \r
485 </programlisting>\r
486                                 <para>Note the <varname>DEFAULT</varname> variables. These allow you to set default for your library or to populate required fields if you data allows \r
487                                 <systemitem>NULL</systemitem> values where fields are required in Evergreen.</para>\r
488                         </step>\r
489                         <step>\r
490                                 <para>Formatting of some fields to fit Evergreen filed formatting may be required. Here is an example of sql to adjust phone numbers in the staging \r
491                                 table to fit the evergreen field:</para>\r
492 <programlisting language="sql">\r
493 UPDATE students phone = replace(replace(replace(rpad(substring(phone from 1 for 9), 10, '-') || \r
494 substring(phone from 10), '(', ''), ')', ''), ' ', '-');\r
495 </programlisting>\r
496                                 <para>Data <quote>massaging</quote> may be required to fit formats used in Evergreen.</para>\r
497                         </step>\r
498                         <step>\r
499                                 <para>Insert records from the staging table into the <link linkend="actor.table.usr">actor.usr</link> Evergreen table:</para>\r
500 <programlisting language="sql">\r
501  INSERT INTO actor.usr (\r
502         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, \r
503         family_name, day_phone, home_ou, claims_returned_count, net_access_level) \r
504         SELECT profile, students.usrname, email, student_id, ident_type, student_id, \r
505         first_name, last_name, phone, home_ou, claims_returned_count, net_access_level \r
506         FROM students;\r
507 </programlisting>                       \r
508                         </step>\r
509                         <step>\r
510                                 <para>insert records into <link linkend="actor.table.card">actor.card</link> from <link linkend="actor.table.usr">actor.usr</link>.</para>\r
511 <programlisting language="sql">\r
512 INSERT INTO actor.card (usr, barcode) \r
513         SELECT actor.usr.id, students.barcode \r
514         FROM students \r
515                 INNER JOIN actor.usr \r
516                         ON students.usrname = actor.usr.usrname;\r
517 </programlisting>               \r
518                                 <para>This assumes a one to one card patron relationship. If your patron data import has multiple cards assigned to one patron more complex import scripts may be required                                      which look for inactive or active flags.</para> \r
519                         </step>\r
520                         <step>\r
521                                 <para>Update actor.usr.card field with actor.card.id to associate active card with the user:</para>\r
522 <programlisting language="sql">\r
523 UPDATE actor.usr \r
524         SET card = actor.card.id \r
525         FROM actor.card \r
526         WHERE actor.card.usr = actor.usr.id;\r
527 </programlisting>                       \r
528                         </step>\r
529                         <step>\r
530                                 <para>Insert records into <link linkend="actor.table.usr-address">actor.usr_address</link> to add address information for users:</para>\r
531 <programlisting language="sql">\r
532 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
533         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, \r
534         students.country, students.postal_code \r
535         FROM students \r
536         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
537 </programlisting>                       \r
538                         </step>\r
539                         <step>\r
540                                 <para>update <link linkend="actor.table.usr-address">actor.usr.address</link> with address id from address table.</para>\r
541 <programlisting language="sql">\r
542 UPDATE actor.usr \r
543         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
544         FROM actor.usr_address \r
545         WHERE actor.usr.id = actor.usr_address.usr;\r
546 </programlisting>       \r
547                         <para>This assumes 1 address per patron. More complex scenarios may require more sophisticated SQL.</para>              \r
548                         </step>\r
549                 </procedure>\r
550                 <simplesect>\r
551                         <title>Creating an sql Script for Importing Patrons</title>\r
552                         <para>The procedure for importing patron can be automated with the help of an sql script. Follow these steps to create an import script:</para>\r
553                 \r
554                         <procedure>\r
555                                 <step>\r
556                                         <para>Create an new file and name it <filename>import.sql</filename></para>\r
557 \r
558                                 </step>\r
559 \r
560                                 <step>\r
561                                         <para>Edit the file to look similar to this:</para>\r
562 <programlisting>\r
563 BEGIN;\r
564 \r
565 -- Create staging table.\r
566 CREATE TABLE students (\r
567         student_id int, barcode text, last_name text, first_name text, email text, address_type text, street1 text, street2 text, \r
568         city text, province text, country text, postal_code text, phone text, profile int, \r
569         ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, \r
570         net_access_level int DEFAULT 2, password text\r
571 ); \r
572 \r
573 \r
574 --Insert records from the staging table into the actor.usr table.\r
575 INSERT INTO actor.usr (\r
576         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, \r
577         day_phone, home_ou, claims_returned_count, net_access_level) \r
578         SELECT profile, students.usrname, email, student_id, ident_type, student_id, first_name, \r
579         last_name, phone, home_ou, claims_returned_count, net_access_level FROM students;\r
580 \r
581 --Insert records from the staging table into the actor.usr table.\r
582 INSERT INTO actor.card (usr, barcode) \r
583         SELECT actor.usr.id, students.barcode \r
584         FROM students \r
585                 INNER JOIN actor.usr \r
586                         ON students.usrname = actor.usr.usrname;\r
587 \r
588 --Update actor.usr.card field with actor.card.id to associate active card with the user:\r
589 UPDATE actor.usr \r
590         SET card = actor.card.id \r
591         FROM actor.card \r
592         WHERE actor.card.usr = actor.usr.id;\r
593 \r
594 --INSERT records INTO actor.usr_address from staging table.\r
595 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
596         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, \r
597         students.country, students.postal_code \r
598         FROM students \r
599         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
600 \r
601 \r
602 --Update actor.usr mailing address with id from actor.usr_address table.:\r
603 UPDATE actor.usr \r
604         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
605         FROM actor.usr_address \r
606         WHERE actor.usr.id = actor.usr_address.usr;\r
607 \r
608 COMMIT;\r
609 </programlisting>\r
610                                         <para>Placing the sql statements between <code>BEGIN;</code> and <code>COMMIT;</code> creates a transaction block so that if any sql statements fail, the \r
611                                         entire process is canceled and the database is rolled back to its original state. Lines beginning with <code>--</code> are comments to let you you what \r
612                                         each sql statement is doing and are not processed.</para> \r
613                                 </step>\r
614                         </procedure>\r
615                 </simplesect>\r
616                 <simplesect>\r
617                         <title>Batch Updating Patron Data</title>\r
618                         <indexterm><primary>migrating</primary><secondary>batch updating patrons</secondary></indexterm>\r
619                         <para>For academic libraries, doing batch updates to add new patrons to the Evergreen database is a critical task. The above procedures and \r
620                         import script can be easily adapted to create an update script for importing new patrons from external databases. If the data import file contains only new patrons, then, \r
621                         the above procedures will work well to insert those patrons. However, if the data load contains all patrons, a second staging table and a procedure to remove existing                          patrons from that second staging table may be required before importing the new patrons. Moreover, additional steps to update address information and perhaps delete \r
622                         inactive patrons may also be desired depending on the requirements of the institution.</para>\r
623                         <para>After developing the scripts to import and update patrons have been created, another important task for library staff is to develop an import strategy and schedule \r
624                         which suits the needs of the library. This could be determined by registration dates of your institution in the case of academic libraries. It is important to balance \r
625                         the convenience of patron loads and the cost of processing these loads vs staff adding patrons manually.</para>   \r
626                </simplesect> \r
627         </section>\r
628         <section xml:id="emptydatabase">\r
629                 <title>Restoring your Evergreen Database to an Empty State</title>\r
630                 <para>If you've done a test import of records and you want to quickly get Evergreen back to a pristine state, you can create a clean Evergreen database schema by performing the \r
631                 following:</para>\r
632                 <procedure>\r
633                         <step> \r
634 <screen>\r
635 <userinput>cd ILS/Open-ILS/src/sql/Pg/</userinput>\r
636 </screen>\r
637                         </step>\r
638                          <step> \r
639                                  <para>Rebuild the database schema:</para>\r
640 <screen>\r
641 <userinput>./build-db.sh [db-hostname> [db-port] [db-name] [db-user] [db-password] [db-version]</userinput>\r
642 </screen>\r
643                                 <caution><para>This will remove all of your data from the database and restore the default values.</para></caution>             \r
644                         </step>\r
645                 </procedure>\r
646         </section>\r
647         <section xml:id="exportingbibrecordsintoMARC">\r
648                 <title>Exporting Bibliographic Records into MARC files</title>\r
649                 <indexterm><primary>migrating</primary><secondary>exporting bibliographic records</secondary><tertiary>MARC</tertiary></indexterm>\r
650                 <para>The following procedure explains how to export Evergreen bibliographic records into MARC files using the marc_export support script. All steps should be performed by the \r
651                 opensrf user from your Evergreen server.</para>\r
652                 <procedure>\r
653                         <step> \r
654                                 <para>Create a text file list of the Bibliographic record ids you would like to export from Evergreen. One way to do this is using SQL:</para>\r
655 <programlisting language="sql">\r
656 SELECT DISTINCT bre.id FROM biblio.record_entry AS bre\r
657         JOIN asset.call_number AS acn ON acn.record-bre.id \r
658         WHERE bre.deleted='false' and ownling_lib=101 \g /home/opensrf/records.txt;\r
659 </programlisting>\r
660                                 <para>This query will create a file called <filename>records.txt</filename> containing a column of distinct ids of items owned by the organizational unit with the \r
661                                 <database class="field">id</database> <literal>101</literal>.</para>\r
662                         </step>\r
663                         <step>\r
664                                 <para>Navigate to the support-scripts folder</para>\r
665 <screen>\r
666 <userinput>cd /home/opensrf/Evergreen-ILS*/Open-ILS/src/support-scripts/</userinput>\r
667 </screen>\r
668                         </step>\r
669                         <step>\r
670                                 <para>Run <command>marc_export</command>, using the id file you created in step 1 to define which files to export.</para>\r
671 <screen>\r
672 <userinput>cat /home/opensrf/records.txt | ./marc_export -i -c /openils/conf/opensrf_core.xml \\r
673 -x /openils/conf/fm_IDL.xml -f XML --timeout 5 > exported_files.xml\r
674 </userinput>\r
675 </screen>\r
676                                 <para>The example above export the records into MARCXML format.</para>\r
677                                 <note>\r
678                                 <para>For help or for more options when running <command>marc_export</command>, run <command>marc_export</command> with the <option>-h</option> option:</para>\r
679 <screen>\r
680 <userinput>./marc_export -h</userinput>\r
681 </screen>\r
682                                 </note>\r
683                                 \r
684                         </step>\r
685                                 <note>\r
686                                 <para>Processing time for exporting records will depond on several factors such as the number of records you are exporting. It is recommended that you divide the \r
687                                 export id files (<filename>records.txt</filename>) into manageable number of records if you are exporting a large number of records.</para> \r
688                                 </note>\r
689                 </procedure>\r
690         </section>      \r
691         <section xml:id="importingauthorityrecords">\r
692                 <title>Importing Authority Records</title>\r
693                 <indexterm><primary>migrating</primary><secondary>importing authority records</secondary></indexterm>\r
694                 <para>The following procedure explains how to export Evergreen bibliographic records into MARC files using the marc_export support script. All steps should be performed by the \r
695                 opensrf user from your Evergreen server.</para>\r
696                 <simplesect>\r
697                         <title>Importing Authority Records from Command Line</title>\r
698                         <para>The major advantages of the command line approach are its speed and its convenience for system administrators who can perform bulk loads of authority records in a \r
699                         controlled environment.</para>          \r
700                         <procedure>\r
701 \r
702                                 <step> \r
703                                         <para>Run <command>marc2are.pl</command> against the authority records, specifying the user name, password, MARC type (USMARC or XML). Use \r
704                                         <varname>STDOUT</varname> redirection \r
705                                         to either pipe the output directly into the next command or into an output file for inspection. For example, to process a set of authority records \r
706                                         named <filename>auth_small.xml</filename> using the default user name and password and directing the output into a file named <filename>auth.are</filename>:</para>\r
707 <screen>\r
708 <userinput>cd Open-ILS/src/extras/import/</userinput>\r
709 <userinput>perl marc2are.pl --user admin --pass open-ils auth_small.xml > auth.are</userinput>\r
710 </screen>\r
711                                 \r
712                                 </step>\r
713 \r
714                                 <step> \r
715                                         <para>Run <command>direct_ingest.pl</command> to ingest records.</para>\r
716 <screen>\r
717 <userinput>perl direct_ingest.pl -a auth.are > ~/auth.ingest</userinput>\r
718 </screen>\r
719                                 </step>\r
720                                 <step> \r
721                                         <para>Run <command>pg_loader.pl</command> to generate the SQL necessary for importing the authority records into your system.</para>\r
722 <screen>\r
723 <userinput>cd Open-ILS/src/extras/import/</userinput>\r
724 <userinput> perl pg_loader.pl-or are -or afr -a afr --output=auth &lt; ~/auth.ingest</userinput>\r
725 </screen>\r
726                                 \r
727                                 </step>\r
728                                 <step> \r
729                                         <para>Load the authority records from the SQL file that you generated in the last step into your Evergreen database using the psql tool. Assuming the default user \r
730                                         name, host name, and database name for an Evergreen instance, that command looks like:</para>\r
731 <screen>\r
732 <userinput>psql -U evergreen -h localhost -d evergreen -f auth.sql</userinput>\r
733 </screen>\r
734                                 \r
735                                 </step>\r
736                         </procedure>\r
737                 </simplesect>\r
738                 <simplesect>\r
739                         <title>Importing authority records using the MARC Batch Import/Export interface from the Staff Client</title>\r
740                         <para>Good for loading batches of up to 5,000 records (roughly) at a time, the major advantages to importing authority records using the MARC Batch Import/Export interface are \r
741                         that it does not require command-line or direct database access – good for both security in that it minimizes the number of people who need this access and for spreading the \r
742                         effort around to others in the library – and it does most of the work (for example, figuring out whether the batch of records is in XML or USMARC format) for you.</para> \r
743                         <para>To import a set of MARC authority records from the MARC Batch Import/Export interface:</para>\r
744                         <procedure>\r
745                                 <step> \r
746                                         <para>From the Evergreen staff client, select <menuchoice><guimenu>Cataloging</guimenu><guimenuitem>MARC Batch Import/Export</guimenuitem></menuchoice>. \r
747                                         The <guilabel>Evergreen MARC File Upload</guilabel> screen opens, with <guilabel>Import Records</guilabel> as the highlighted tab.</para>\r
748                                 </step>\r
749                                 <step> \r
750                                         <para>From the <guimenu>Bibliographic records</guimenu> drop-down menu, select <guimenuitem>Authority records</guimenuitem>.</para>\r
751                                 \r
752                                 </step>\r
753                                 <step> \r
754                                         <para>Enter a name for the queue (batch import job) in the <guilabel>Create a new upload queue</guilabel> field.</para>\r
755                                 \r
756                                 </step>\r
757                                 <step> \r
758                                         <para>Select the <guilabel>Auto-Import Non-Colliding Records</guilabel> checkbox.</para>\r
759                                 \r
760                                 </step>\r
761                                 <step> \r
762                                         <para>Click the <guibutton>Browse…</guibutton> button to select the file of MARC authorities to import.</para>\r
763                                 \r
764                                 </step>\r
765                                 <step> \r
766                                         <para>Click the <guibutton>Upload</guibutton> button to begin importing the records. The screen displays <guilabel>Uploading…</guilabel>\r
767                                         <guilabel>Processing…</guilabel> to show that the records are being transferred to the server, then displays a progress bar to show the actual import \r
768                                         progress. When the staff client displays the progress bar, you can disconnect your staff client safely. Very large batches of records might time out at this \r
769                                         stage.</para>\r
770                                 \r
771                                 </step>\r
772                                 <step> \r
773                                         <para>Once the import is finished, the staff client displays the results of the import process. You can manually display the import progress by selecting \r
774                                         the <guilabel>Inspect Queue</guilabel> tab of the MARC Batch Import/Export interface and selecting the queue name. By default, the staff client does not \r
775                                         display records that were imported successfully; it only shows records that conflicted with existing entries in the database. The screen shows the overall \r
776                                         status of the import process in the top right-hand corner, with the <guilabel>Total</guilabel> and <guilabel>Imported</guilabel> number of records for the \r
777                                         queue.</para>\r
778                                 </step>\r
779                         </procedure>\r
780 \r
781                 </simplesect>\r
782 \r
783         </section>\r
784 </chapter>\r
785    \r
786       \r
787 \r
788 \r
789  \r
790 \r
791 \r