-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathks.auto_add.sh
executable file
·163 lines (152 loc) · 7.75 KB
/
ks.auto_add.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# ***************************************************************************
# Automatisches Indexieren neuer Webschnitte in PyWB
# Autor: Ingolf Kuss
# Änderungshistorie:
# +------------------+------------+-----------------------------------------+
# | Autor | Datum | Beschreibung |
# +------------------+------------+-----------------------------------------+
# | Ingolf Kuss | 16.09.2019 | Neuanlage |
# | Ingolf Kuss | 16.01.2020 | vervollständigt |
# | Ingolf Kuss | 22.05.2020 | Anpassungen für wayback-test im Betrieb mit edoweb-test
# | Ingolf Kuss | 26.04.2022 | Maximale Häppchengröße für den aktuellen Index index.cdxj eingeführt.
# | | | Bei Überschreiten der max. Größe wird ein neuen Index angefangen.
# +------------------+------------+-----------------------------------------+
# ***************************************************************************
# Aktualisiert index.cdxj. Maximale Indexgröße 10 GB (Größe anpassbar in der Shell-Variable 'happengroesse').
# Die einzelnen Teilindexe werden index01.cdxj, index02.cdxj, ... genannt; der letzte (< 10 GB) index.cdxj
data_basedir=/data
#data_basedir=/opt/toscience
happengroesse=10000000000 # Dateigröße in Byte
#happengroesse=2000000000 # Dateigröße in Byte
#happengroesse=1000000000 # Dateigröße in Byte
pywb_basedir=/opt/pywb
collections=$pywb_basedir/collections
archive_lesesaal=$collections/wayback/archive
archive_weltweit=$collections/public/archive
logfile=$pywb_basedir/logs/ks.auto_add.log
echo "" >> $logfile
echo "********************************************************************************" >> $logfile
echo `date`
echo `date` >> $logfile
echo "START Auto adding new web harvests"
echo "START Auto adding new web harvests" >> $logfile
echo "Max. Indexgröße = $happengroesse Bytes" >> $logfile
echo "********************************************************************************" >> $logfile
actdir=$PWD
# bash-Funktionen
function update_collection {
# Aktualisiert alle neu hinzugekommenen oder kürzlich geänderten Webarchivdateien eines Verzeichnisses (z.B. wpull-data/) in einem pywb-Archiv (u.a. pywb-Index)
local dataverz=$1;
local suchmuster=$2;
local archivename=$3
local archive=$4;
# Schleife über alle im Datenverzeichnis angelegten WARC-Dateien
cd $dataverz
for warcfile in $suchmuster ; do
# echo "warcfile=$dataverz/$warcfile" >> $logfile
if [ "$warcfile" = "$suchmuster" ]; then
# echo "Sammlung $archivename, Verzeichnis $dataverz: keine WARC-Datei gefunden."
break
fi
warcbase=`basename $warcfile`
# Gibt es schon eine gleichnamige Datei oder einen gleichnamigen symbolischen Link im Archiv ?
if [ -f $archive/$warcbase ]; then
# echo "Archivfile existiert" >> $logfile
# Wenn es kein symbolischer Link ist, ist es eine echte Datei.
# In diesem Falle ist noch ein Indexierungsjob bei der Arbeit und es darf kein weiterer angestoßen werden.
if [ ! -h $archive/$warcbase ]; then
continue
fi
# Ist das Archivfile neuer ?
if test `find $archive/$warcbase -prune -newer $dataverz/$warcfile`; then
# echo "Archivfile ist neuer. Nichts zu tun." >> $logfile
continue
fi
echo "Archivfile ist älter" >> $logfile
# Archivfile (symbolischer Link) löschen
rm $archive/$warcbase
fi
# Archivfile exsitiert noch nicht oder ist älter
echo "warcfile=$dataverz/$warcfile" >> $logfile
echo "Warcfile wird hinzugefügt." >> $logfile
/opt/pywb/bin/ks.add_warc.sh $archivename $dataverz/$warcfile >> $logfile
done
}
function rename_large_index {
local coll=$1;
collection=$collections/$coll
cd $collection/indexes
size=0
if [ -f "index.cdxj" ]; then
for word in `du -b index.cdxj`; do size=$word; break; done
fi
if [ $size -gt $happengroesse ]; then
echo "Größe des aktuellen Index ($size Byte) überschreitet Portionsgröße ($happengroesse Byte)." >> $logfile
# Ermittle nächste Happennummer
last_indexname="index00.cdxj"
if [ -f "index01.cdxj" ]; then
for word in `ls index??.cdxj | sort -r`; do last_indexname=$word; break; done
fi
echo "Last Indexname: $last_indexname" >> $logfile
last_index_nr=0
if [[ "$last_indexname" =~ index(..).cdxj ]]; then
last_index_nr=${BASH_REMATCH[1]}
fi
echo "Last index no: $last_index_nr" >> $logfile
next_happen_nummer=$last_index_nr
((next_happen_nummer++))
echo "Next index no: $next_happen_nummer" >> $logfile
# Aktuellen Index umbenennen nach printf("index%02d.cdxj", $next_happen_nummer)
printf -v newIndexName 'index%02d.cdxj' $next_happen_nummer
mv index.cdxj $newIndexName
echo "Aktuellen Index index.cdxj umbenannt nach $newIndexName" >> $logfile
fi
}
# ************************
# Beginn Hauptverarbeitung
# ************************
# I. Lesesaal-Sammlung
# I.1. Ggfs. Umbenennung des aktuellen Index, falls dieser schon zu groß ist
# Es wird dann automatisch ein neuer Index index.cdxj begonnen.
rename_large_index wayback
# I.2 Neuindexierung der neu hinzu gekommenen WARC-Archive in der Lesesaal-Sammlung
# i. wpull-data
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
echo "START auto-indexing new wpull harvests" >> $logfile
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
update_collection $data_basedir/wpull-data "*:*/20*/*.warc.gz" wayback $archive_lesesaal
# ii. heritrix-data
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
echo "START auto-indexing new heritrix harvests" >> $logfile
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
update_collection $data_basedir/heritrix-data "*:*/20*/warcs/*.warc.gz" wayback $archive_lesesaal
# iii. cdn-data
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
echo "START auto-indexing new cdn harvests in restricted access collection" >> $logfile
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
update_collection $data_basedir/cdn-data "*:*/20*/*.warc.gz" wayback $archive_lesesaal
# II. Weltweit-Sammlung
# II.1. Ggfs. Umbenennung des aktuellen Index, falls dieser schon zu groß ist
# Es wird dann automatisch ein neuer Index index.cdxj begonnen.
rename_large_index public
# II.2 Neuindexierung der neu hinzu gekommenen WARC-Archive in der Weltweit-Sammlung
# i. cdn-data
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
echo "START auto-indexing new cdn harvests in public collection" >> $logfile
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
update_collection $data_basedir/cdn-data "*:*/20*/*.warc.gz" public $archive_weltweit
# ii. public-data
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
echo "START auto-indexing new public harvests (soft links)" >> $logfile
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >> $logfile
update_collection $data_basedir/public-data "*:*/20*/*.warc.gz" public $archive_weltweit
update_collection $data_basedir/public-data "*:*/20*/warcs/*.warc.gz" public $archive_weltweit
echo "********************************************************************************" >> $logfile
echo `date`
echo `date` >> $logfile
echo "ENDE Auto adding new web harvests"
echo "ENDE Auto adding new web harvests" >> $logfile
echo "********************************************************************************" >> $logfile
cd $actdir
exit 0