]> git.evergreen-ils.org Git - working/Evergreen.git/blob - 1.6/admin/migratingdata_1.6.xml
Add upgrading to 2.0 Documentation.
[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 call_num 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_call_num, 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_call_num, 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>COMMIT;</emphasis>\r
341 </programlisting>\r
342                         <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
343                                 copy to the bibliographic record. Please refer to <link linkend="migratingbibrecordcopies">for the steps to import your holdings into Evergreen.</link></para> \r
344                         </step>\r
345                 </procedure>\r
346                 \r
347         </section>\r
348         <section xml:id="migratingbibrecordcopies">\r
349                 <title>Adding Copies to Bibliographic Records</title><indexterm><primary>migrating</primary><secondary>holdings</secondary></indexterm> \r
350                 <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
351                 to holdings maintenance.</para> \r
352                 <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
353                 for the specific data in your holdings.</para>  \r
354                 <procedure>\r
355                         <step>\r
356                                 <para>Create a staging_items staging table to hold the holdings data:</para>\r
357 <programlisting language="sql">\r
358 CREATE TABLE staging_items (\r
359         callnum text, -- call number label\r
360         hseq int, -- call number label\r
361         egid  int,  -- biblio.record_entry_id\r
362         createdate      date,\r
363         location        text,\r
364         barcode         text,\r
365         item_type       text,\r
366         owning_lib      text  -- actor.org_unit.shortname\r
367 );\r
368 </programlisting>\r
369                         </step> \r
370                         <step>\r
371                                 <para>Import the items using the HOLDINGS.pg SQL script created using the extract_holdings utility.</para>\r
372 <screen>\r
373 <userinput>psql -U evergreen -f HOLDINGS.pg evergreen</userinput>\r
374 </screen>\r
375                                 <para>the file <filename>HOLDINGS.pg</filename> and/or the COPY query may need to be adjusted for your particular circumstances.</para>  \r
376                         </step>\r
377                         \r
378 \r
379                         <step>\r
380                                 <para>Generate shelving locations from your staging table.</para>\r
381 <programlisting language="sql">\r
382 INSERT INTO asset.copy_location (name, owning_lib)\r
383 SELECT  DISTINCT l.location, ou.id\r
384 FROM  staging_items l \r
385        JOIN actor.org_unit ou   ON (l.owning_lib = ou.shortname); \r
386 </programlisting>\r
387                         </step>\r
388                         <step>\r
389                                 <para>Generate circulation modifiers from your staging table.</para>\r
390 <programlisting language="sql">\r
391 INSERT INTO config.circ_modifier (code, name, description, sip2_media_type, magnetic_media)\r
392         SELECT  DISTINCT item_type AS code,\r
393           item_type AS name,\r
394           LOWER(item_type) AS description,\r
395           '001' AS sip2_media_type,\r
396           FALSE AS magnetic_media\r
397           FROM  staging_items\r
398           WHERE item_type NOT IN (SELECT code FROM config.circ_modifier);\r
399 </programlisting>\r
400                         </step>\r
401                         <step>\r
402                                 <para>Generate call numbers from your staging table:</para>\r
403 <programlisting language="sql">\r
404 INSERT INTO asset.call_number (creator,editor,record,label,owning_lib)\r
405 SELECT  DISTINCT 1, 1, b.id, l.callnum, ou.id\r
406 FROM  staging.staging_items l\r
407 JOIN actor.org_unit ou ON (l.owning_lib = ou.shortname);\r
408 </programlisting>\r
409                         </step>\r
410                         <step>\r
411                                 <para>Generate copies from your staging table:</para>\r
412 <programlisting language="sql">\r
413 INSERT INTO asset.copy (\r
414 circ_lib, creator, editor, create_date, barcode,\r
415 STATUS, location, loan_duration, fine_level, circ_modifier, deposit, ref, call_number)          \r
416 \r
417 SELECT  DISTINCT ou.id AS circ_lib,\r
418         1 AS creator,\r
419         1 AS editor,\r
420         l.createdate AS create_date,\r
421         l.barcode AS barcode,\r
422         0 AS STATUS,\r
423         cl.id AS location,\r
424         2 AS loan_duration,\r
425         2 AS fine_level,\r
426         l.item_type AS circ_modifier,\r
427         FALSE AS deposit,\r
428         CASE\r
429         WHEN l.item_type = 'REFERENCE' THEN TRUE\r
430         ELSE FALSE\r
431         END AS ref,                                             \r
432         cn.id AS call_number\r
433         FROM  staging.staging_items l\r
434         JOIN actor.org_unit ou\r
435                 ON (l.owning_lib = ou.shortname)\r
436         JOIN asset.copy_location cl\r
437                 ON (ou.id = cl.owning_lib AND l.location = cl.name)\r
438         JOIN asset.call_number cn\r
439                 ON (ou.id = cn.owning_lib      \r
440                 AND l.callnum = cn.label);\r
441 </programlisting>\r
442                                 <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
443                         </step>\r
444                 </procedure>\r
445         </section>\r
446         <section xml:id="migratingpatrons">\r
447                 <title>Migrating Patron Data</title>\r
448                 <indexterm><primary>migrating</primary><secondary>patrons</secondary></indexterm>\r
449                 <para>\r
450                 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
451                 It does not deal with the process of exporting from the non-Evergreen \r
452                 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
453                 academic records.               \r
454                 </para>\r
455                 <para>When importing records into Evergreen you will need to populate 3 tables in your Evergreen database:</para>\r
456                 <itemizedlist>\r
457                         <listitem><link linkend="actor.table.usr">actor.usr</link> - The main table for user data</listitem>\r
458                         <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
459                         <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
460                 </itemizedlist>\r
461                 <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
462                 for data to include \r
463                 in your import. It is important to understand the data types and constraints on each field.</para>\r
464                 <procedure>\r
465                         <step>\r
466                                 <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
467                                  the records should use Unicode (UTF8) <indexterm><primary>Unicode</primary></indexterm> character encoding.</para>\r
468                         </step>\r
469                         <step>\r
470                                 <para>Create a staging table.<indexterm><primary>staging table</primary></indexterm>  A staging table will allow you to tweak the data before importing. \r
471                                 Here is an example sql statement:</para>\r
472                                 <indexterm><primary>sql</primary></indexterm> \r
473 <programlisting language="sql">\r
474 CREATE TABLE students (\r
475          student_id int, barcode text, last_name text, first_name text, program_number text, \r
476         program_name text, email text, address_type text, street1 text, street2 text, \r
477         city text, province text, country text, postal_code text, phone text, profile int, \r
478         ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, \r
479         net_access_level int DEFAULT 2, password text\r
480 ); \r
481 </programlisting>\r
482                                 <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
483                                 <systemitem>NULL</systemitem> values where fields are required in Evergreen.</para>\r
484                         </step>\r
485                         <step>\r
486                                 <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
487                                 table to fit the evergreen field:</para>\r
488 <programlisting language="sql">\r
489 UPDATE students phone = replace(replace(replace(rpad(substring(phone from 1 for 9), 10, '-') || \r
490 substring(phone from 10), '(', ''), ')', ''), ' ', '-');\r
491 </programlisting>\r
492                                 <para>Data <quote>massaging</quote> may be required to fit formats used in Evergreen.</para>\r
493                         </step>\r
494                         <step>\r
495                                 <para>Insert records from the staging table into the <link linkend="actor.table.usr">actor.usr</link> Evergreen table:</para>\r
496 <programlisting language="sql">\r
497  INSERT INTO actor.usr (\r
498         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, \r
499         family_name, day_phone, home_ou, claims_returned_count, net_access_level) \r
500         SELECT profile, students.usrname, email, student_id, ident_type, student_id, \r
501         first_name, last_name, phone, home_ou, claims_returned_count, net_access_level \r
502         FROM students;\r
503 </programlisting>                       \r
504                         </step>\r
505                         <step>\r
506                                 <para>insert records into <link linkend="actor.table.card">actor.card</link> from <link linkend="actor.table.usr">actor.usr</link>.</para>\r
507 <programlisting language="sql">\r
508 INSERT INTO actor.card (usr, barcode) \r
509         SELECT actor.usr.id, students.barcode \r
510         FROM students \r
511                 INNER JOIN actor.usr \r
512                         ON students.usrname = actor.usr.usrname;\r
513 </programlisting>               \r
514                                 <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
515                         </step>\r
516                         <step>\r
517                                 <para>Update actor.usr.card field with actor.card.id to associate active card with the user:</para>\r
518 <programlisting language="sql">\r
519 UPDATE actor.usr \r
520         SET card = actor.card.id \r
521         FROM actor.card \r
522         WHERE actor.card.usr = actor.usr.id;\r
523 </programlisting>                       \r
524                         </step>\r
525                         <step>\r
526                                 <para>Insert records into <link linkend="actor.table.usr-address">actor.usr_address</link> to add address information for users:</para>\r
527 <programlisting language="sql">\r
528 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
529         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, \r
530         students.country, students.postal_code \r
531         FROM students \r
532         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
533 </programlisting>                       \r
534                         </step>\r
535                         <step>\r
536                                 <para>update <link linkend="actor.table.usr-address">actor.usr.address</link> with address id from address table.</para>\r
537 <programlisting language="sql">\r
538 UPDATE actor.usr \r
539         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
540         FROM actor.usr_address \r
541         WHERE actor.usr.id = actor.usr_address.usr;\r
542 </programlisting>       \r
543                         <para>This assumes 1 address per patron. More complex scenarios may require more sophisticated SQL.</para>              \r
544                         </step>\r
545                 </procedure>\r
546                 <simplesect>\r
547                         <title>Creating an sql Script for Importing Patrons</title>\r
548                         <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
549                 \r
550                         <procedure>\r
551                                 <step>\r
552                                         <para>Create an new file and name it <filename>import.sql</filename></para>\r
553 \r
554                                 </step>\r
555 \r
556                                 <step>\r
557                                         <para>Edit the file to look similar to this:</para>\r
558 <programlisting>\r
559 BEGIN;\r
560 \r
561 -- Create staging table.\r
562 CREATE TABLE students (\r
563         student_id int, barcode text, last_name text, first_name text, program_number text, \r
564         program_name text, email text, address_type text, street1 text, street2 text, \r
565         city text, province text, country text, postal_code text, phone text, profile int, \r
566         ident_type int, home_ou int, claims_returned_count int DEFAULT 0, usrname text, \r
567         net_access_level int DEFAULT 2, password text\r
568 ); \r
569 \r
570 \r
571 --Insert records from the staging table into the actor.usr table.\r
572 INSERT INTO actor.usr (\r
573         profile, usrname, email, passwd, ident_type, ident_value, first_given_name, family_name, \r
574         day_phone, home_ou, claims_returned_count, net_access_level) \r
575         SELECT profile, students.usrname, email, student_id, ident_type, student_id, first_name, \r
576         last_name, phone, home_ou, claims_returned_count, net_access_level FROM students;\r
577 \r
578 --Insert records from the staging table into the actor.usr table.\r
579 INSERT INTO actor.card (usr, barcode) \r
580         SELECT actor.usr.id, students.barcode \r
581         FROM students \r
582                 INNER JOIN actor.usr \r
583                         ON students.usrname = actor.usr.usrname;\r
584 \r
585 --Update actor.usr.card field with actor.card.id to associate active card with the user:\r
586 UPDATE actor.usr \r
587         SET card = actor.card.id \r
588         FROM actor.card \r
589         WHERE actor.card.usr = actor.usr.id;\r
590 \r
591 --INSERT records INTO actor.usr_address from staging table.\r
592 INSERT INTO actor.usr_address (usr, street1, street2, city, state, country, post_code) \r
593         SELECT actor.usr.id, students.street1, students.street2, students.city, students.province, \r
594         students.country, students.postal_code \r
595         FROM students \r
596         INNER JOIN actor.usr ON students.usrname = actor.usr.usrname;\r
597 \r
598 \r
599 --Update actor.usr mailing address with id from actor.usr_address table.:\r
600 UPDATE actor.usr \r
601         SET mailing_address = actor.usr_address.id, billing_address = actor.usr_address.id \r
602         FROM actor.usr_address \r
603         WHERE actor.usr.id = actor.usr_address.usr;\r
604 \r
605 COMMIT;\r
606 </programlisting>\r
607                                         <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
608                                         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
609                                         each sql statement is doing and are not processed.</para> \r
610                                 </step>\r
611                         </procedure>\r
612                 </simplesect>\r
613                 <simplesect>\r
614                         <title>Batch Updating Patron Data</title>\r
615                         <indexterm><primary>migrating</primary><secondary>batch updating patrons</secondary></indexterm>\r
616                         <para>For academic libraries, doing batch updates to add new patrons to the Evergreen database is a critical task. The above procedures and \r
617                         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
618                         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
619                         inactive patrons may also be desired depending on the requirements of the institution.</para>\r
620                         <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
621                         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
622                         the convenience of patron loads and the cost of processing these loads vs staff adding patrons manually.</para>   \r
623                </simplesect> \r
624         </section>\r
625         <section xml:id="emptydatabase">\r
626                 <title>Restoring your Evergreen Database to an Empty State</title>\r
627                 <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
628                 following:</para>\r
629                 <procedure>\r
630                         <step> \r
631 <screen>\r
632 <userinput>cd ILS/Open-ILS/src/sql/Pg/</userinput>\r
633 </screen>\r
634                         </step>\r
635                          <step> \r
636                                  <para>Rebuild the database schema:</para>\r
637 <screen>\r
638 <userinput>./build-db.sh [db-hostname> [db-port] [db-name] [db-user] [db-password] [db-version]</userinput>\r
639 </screen>\r
640                                 <caution><para>This will remove all of your data from the database and restore the default values.</para></caution>             \r
641                         </step>\r
642                 </procedure>\r
643         </section>\r
644         <section xml:id="exportingbibrecordsintoMARC">\r
645                 <title>Exporting Bibliographic Records into MARC files</title>\r
646                 <indexterm><primary>migrating</primary><secondary>exporting bibliographic records</secondary><tertiary>MARC</tertiary></indexterm>\r
647                 <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
648                 opensrf user from your Evergreen server.</para>\r
649                 <procedure>\r
650                         <step> \r
651                                 <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
652 <programlisting language="sql">\r
653 SELECT DISTINCT bre.id FROM biblio.record_entry AS bre\r
654         JOIN asset.call_number AS acn ON acn.record-bre.id \r
655         WHERE bre.deleted='false' and ownling_lib=101 \g /home/opensrf/records.txt;\r
656 </programlisting>\r
657                                 <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
658                                 <database class="field">id</database> <literal>101</literal>.</para>\r
659                         </step>\r
660                         <step>\r
661                                 <para>Navigate to the support-scripts folder</para>\r
662 <screen>\r
663 <userinput>cd /home/opensrf/Evergreen-ILS*/Open-ILS/src/support-scripts/</userinput>\r
664 </screen>\r
665                         </step>\r
666                         <step>\r
667                                 <para>Run <command>marc_export</command>, using the id file you created in step 1 to define which files to export.</para>\r
668 <screen>\r
669 <userinput>cat /home/opensrf/records.txt | ./marc_export -i -c /openils/conf/opensrf_core.xml \\r
670 -x /openils/conf/fm_IDL.xml -f XML --timeout 5 > exported_files.xml\r
671 </userinput>\r
672 </screen>\r
673                                 <para>The example above export the records into MARCXML format.</para>\r
674                                 <note>\r
675                                 <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
676 <screen>\r
677 <userinput>./marc_export -h</userinput>\r
678 </screen>\r
679                                 </note>\r
680                                 \r
681                         </step>\r
682                                 <note>\r
683                                 <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
684                                 export id files (<filename>records.txt</filename>) into manageable number of records if you are exporting a large number of records.</para> \r
685                                 </note>\r
686                 </procedure>\r
687         </section>      \r
688         <section xml:id="importingauthorityrecords">\r
689                 <title>Importing Authority Records</title>\r
690                 <indexterm><primary>migrating</primary><secondary>importing authority records</secondary></indexterm>\r
691                 <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
692                 opensrf user from your Evergreen server.</para>\r
693                 <simplesect>\r
694                         <title>Importing Authority Records from Command Line</title>\r
695                         <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
696                         controlled environment.</para>          \r
697                         <procedure>\r
698 \r
699                                 <step> \r
700                                         <para>Run <command>marc2are.pl</command> against the authority records, specifying the user name, password, MARC type (USMARC or XML). Use \r
701                                         <varname>STDOUT</varname> redirection \r
702                                         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
703                                         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
704 <screen>\r
705 <userinput>cd Open-ILS/src/extras/import/</userinput>\r
706 <userinput>perl marc2are.pl --user admin --pass open-ils auth_small.xml > auth.are</userinput>\r
707 </screen>\r
708                                 \r
709                                 </step>\r
710 \r
711                                 <step> \r
712                                         <para>Run <command>direct_ingest.pl</command> to ingest records.</para>\r
713 <screen>\r
714 <userinput>perl direct_ingest.pl -a auth.are > ~/auth.ingest</userinput>\r
715 </screen>\r
716                                 </step>\r
717                                 <step> \r
718                                         <para>Run <command>pg_loader.pl</command> to generate the SQL necessary for importing the authority records into your system.</para>\r
719 <screen>\r
720 <userinput>cd Open-ILS/src/extras/import/</userinput>\r
721 <userinput> perl pg_loader.pl-or are -or afr -a afr --output=auth &lt; ~/auth.ingest</userinput>\r
722 </screen>\r
723                                 \r
724                                 </step>\r
725                                 <step> \r
726                                         <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
727                                         name, host name, and database name for an Evergreen instance, that command looks like:</para>\r
728 <screen>\r
729 <userinput>psql -U evergreen -h localhost -d evergreen -f auth.sql</userinput>\r
730 </screen>\r
731                                 \r
732                                 </step>\r
733                         </procedure>\r
734                 </simplesect>\r
735                 <simplesect>\r
736                         <title>Importing authority records using the MARC Batch Import/Export interface from the Staff Client</title>\r
737                         <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
738                         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
739                         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
740                         <para>To import a set of MARC authority records from the MARC Batch Import/Export interface:</para>\r
741                         <procedure>\r
742                                 <step> \r
743                                         <para>From the Evergreen staff client, select <menuchoice><guimenu>Cataloging</guimenu><guimenuitem>MARC Batch Import/Export</guimenuitem></menuchoice>. \r
744                                         The <guilabel>Evergreen MARC File Upload</guilabel> screen opens, with <guilabel>Import Records</guilabel> as the highlighted tab.</para>\r
745                                 </step>\r
746                                 <step> \r
747                                         <para>From the <guimenu>Bibliographic records</guimenu> drop-down menu, select <guimenuitem>Authority records</guimenuitem>.</para>\r
748                                 \r
749                                 </step>\r
750                                 <step> \r
751                                         <para>Enter a name for the queue (batch import job) in the <guilabel>Create a new upload queue</guilabel> field.</para>\r
752                                 \r
753                                 </step>\r
754                                 <step> \r
755                                         <para>Select the <guilabel>Auto-Import Non-Colliding Records</guilabel> checkbox.</para>\r
756                                 \r
757                                 </step>\r
758                                 <step> \r
759                                         <para>Click the <guibutton>Browse…</guibutton> button to select the file of MARC authorities to import.</para>\r
760                                 \r
761                                 </step>\r
762                                 <step> \r
763                                         <para>Click the <guibutton>Upload</guibutton> button to begin importing the records. The screen displays <guilabel>Uploading…</guilabel>\r
764                                         <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
765                                         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
766                                         stage.</para>\r
767                                 \r
768                                 </step>\r
769                                 <step> \r
770                                         <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
771                                         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
772                                         display records that were imported successfully; it only shows records that conflicted with existing entries in the database. The screen shows the overall \r
773                                         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
774                                         queue.</para>\r
775                                 </step>\r
776                         </procedure>\r
777 \r
778                 </simplesect>\r
779 \r
780         </section>\r
781 </chapter>\r
782    \r
783       \r
784 \r
785 \r
786  \r
787 \r
788 \r