forked from lobbywatch/lobbywatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_db_export.sh
executable file
·613 lines (562 loc) · 21.2 KB
/
run_db_export.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
#!/bin/bash
# Call for production
# ./run_db_export.sh -v -t -d=lobbywat_lobbywatch --user-prefix=reader_ -p
# Include common functions
. common.sh
enable_fail_onerror
if [[ "$USER" == "lobbywat" ]]; then
PHP='php74 -d error_reporting=E_ALL'
else
PHP='php -d error_reporting=E_ALL'
fi
LS='ls -Alh'
ZIP='zip -j -9'
ZIP_TREE='zip -9'
EXPORT=export
EXPORT_LOG=$EXPORT/db_export.txt
MERKBLATT="docs/lobbywatch_daten_merkblatt.pdf"
DATAMODEL="lobbywatch_datenmodell_simplified.pdf"
DOCS="$MERKBLATT $DATAMODEL"
DOCU=docu
DOCU_MD="md"
BASE_FILE_SECRET_DIR=".exports_secret_dir"
BASE_FILE_SECRET_PUBLISH_DIR=".exports_secret_publish_dir"
SECRET_DIR_PATTERN="__secret_dir__"
# DUMP_DIR="$HOME/dev/web/lobbywatch/lobbydev/prod_bak/bak/"
DUMP_DIR="/home/lobbywat/sql_scripts/bak/"
mkdir -p $EXPORT
echo -e "Lobbywatch DB Export" >$EXPORT_LOG
echo -e "====================" >>$EXPORT_LOG
echo >>$EXPORT_LOG
test_parameter=''
isExport=true
isBackupCopy=false
export_options=''
publish=false
publish_dir=''
param_schema=''
db_schema='lobbywatchtest'
param_db=''
param_user_prefix=''
all_data='--slow'
export_formats='-c -s -m -g -j -o -l --arangodb -x -t'
basic_export=false
refresh=false
publish_to_secret_dir=false
secret_dir=''
init_files=false
# http://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
while test $# -gt 0; do
case $1 in
-h | --help)
echo "Export Lobbywatch DB"
echo
echo "$0 [options]"
echo
echo "Options:"
echo "-e LIST Type of data to export, add this type of data -e hist, -e intern, -e unpubl, -e hist+unpubl+intern (default: filter at most)"
echo "-c Copy backups (DB dump)"
echo "-t, --test Test mode: print DB views comments JSON (implies -n)"
echo "-n, --limit Limit number of records"
echo "-p[=DIR], --publish[=DIR] Publish exports to public folder, $SECRET_DIR_PATTERN is substituted by the generated secret dir (default: env LW_PUBLIC_EXPORTS_DIR='$LW_PUBLIC_EXPORTS_DIR'"
echo "-s FILE Publish to a secret directory using key from FILE, the secret changes every Monday"
echo "-S FILE Publish to a secret directory using key from FILE, the secret changes every day"
echo "-1 FILE Publish to a secret directory using key from FILE, the secret changes every 1h"
echo "-r, --refresh Refresh views"
echo "-b, --basic Export only basic formats (CSV, SQL, JSON, GraphML)"
echo "-d=SCHEMA DB schema (default SCHEMA: lobbywatchtest)"
echo "--user-prefix=USER Prefix for db user in settings.php (default: reader_)"
echo "--db=DB DB name for settings.php"
echo "-v [LEVEL], --verbose [LEVEL] Verbose mode (Default level=1)"
echo "-i, --init Init secret files"
echo "-h, --help Show help"
quit
;;
-d=*)
db_schema="${1#*=}"
param_schema="-d=$db_schema"
shift
;;
--user-prefix=*)
param_user_prefix="--user-prefix=${1#*=}"
shift
;;
--db=*)
param_db="--db=${1#*=}"
shift
;;
-r | --refresh)
refresh=true
shift
;;
-i | --init)
init_files=true
shift
;;
-b | --basic)
export_formats='-c -s -m -j'
basic_export=true
shift
;;
-p | --publish)
publish=true
shift
;;
-p=* | --publish=*)
publish_dir="${1#*=}"
publish=true
shift
;;
-t | --test)
test_parameter="-n --comments"
all_data=''
shift
;;
-c)
isBackupCopy=true
isExport=false
shift
;;
-n | --limit)
test_parameter="-n"
all_data=''
shift
;;
-e)
isExport=true
isBackupCopy=false
export_options=$2
shift
shift
;;
-s | -S | -1)
publish_to_secret_dir=true
key=$(cat $2)
# Keyed-Hash Message Authentication Code (HMAC)
# %Y: 4 digit year, %G: 4 digit year of ISO work week
# %V ISO week number, with Monday as first day of week (01..53)
# %m: 2 digit month, %S: 2 digit seconds, %M: 2 digits minutes, %d: 2 digit day, %H: 2 digit hour (24H)
if [[ "$1" == "-s" ]]; then
sha_input="${key}_$(date +%G-%V)"
elif [[ "$1" == "-S" ]]; then
sha_input="${key}_$(date +%Y-%m-%d)"
else
sha_input="${key}_$(date '+%Y-%m-%dT%H')"
fi
# TODO change to hash_hmac
secret_dir=$($PHP -r "print(rtrim(strtr(base64_encode(sha1('$sha_input', true)), '+/', '-_'), '='));")
shift
shift
;;
-v | --verbose)
verbose=true
if [[ $2 =~ ^-?[0-9]+$ ]]; then
verbose_level=$2
verbose_mode="-v=$verbose_level"
shift
else
verbose_level=1
fi
shift
;;
*)
break
;;
esac
done
checkLocalMySQLRunning
START_OVERALL=$(date +%s)
if $refresh; then
echo -e "$(date '+%F %T') Refresh DB '$db_schema' ..."
./run_db_script.sh $db_schema lobbywat_script db_views.sql cronverbose
fi
export_type=''
if [ "$export_options" != "" ]; then
export_type="_$export_options"
elif $isBackupCopy; then
export_type="_dump"
fi
if [[ "$publish_dir" == "" ]]; then
if [[ "$LW_PUBLIC_EXPORTS_DIR" == "" ]]; then
echo -e "\nERROR: LW_PUBLIC_EXPORTS_DIR environment variable is not set"
abort
else
publish_dir=$LW_PUBLIC_EXPORTS_DIR
fi
fi
base_secret_dir=${publish_dir%$SECRET_DIR_PATTERN*}
publish_dir=${publish_dir/$SECRET_DIR_PATTERN/$secret_dir}
if $publish && $publish_to_secret_dir; then
file_secret_dir="$BASE_FILE_SECRET_DIR$export_type"
file_secret_publish_dir="$BASE_FILE_SECRET_PUBLISH_DIR$export_type"
[ -f $file_secret_dir ] && old_secret_dir=$(cat $file_secret_dir) || old_secret_dir=''
[ -f $file_secret_publish_dir ] && old_secret_export_dir=$(cat $file_secret_publish_dir) || old_secret_export_dir=''
if [[ "$old_secret_dir" == "" ]] && ! $init_files; then
echo "'$file_secret_dir' does not exist"
echo "Call with -i for init"
abort
elif [[ "$old_secret_dir" == "" ]] && $init_files; then
echo "Init '$file_secret_dir' since it does not exist yet"
mkdir -p "$publish_dir"
elif [[ "$old_secret_export_dir" != "$publish_dir" ]]; then
echo -e "Publish dir path changed\n$old_secret_export_dir to\n$publish_dir"
if [[ "$old_secret_dir" != "$secret_dir" ]]; then
echo -e "mv $base_secret_dir$old_secret_dir -> $base_secret_dir$secret_dir"
mv "$base_secret_dir$old_secret_dir" "$base_secret_dir$secret_dir"
else
echo -e "Cannot rename publish dir.\nMove manually:"
echo "mv -i $old_secret_export_dir $publish_dir"
abort
fi
fi
echo "$secret_dir" >$file_secret_dir
echo "$publish_dir" >$file_secret_publish_dir
fi
if [[ $publish && ! -d $publish_dir ]]; then
echo "Publish dir '$publish_dir' does not exist"
abort
fi
if $isExport; then
echo -e "$(date '+%F %T') Start exporting..."
$PHP -f db_export.php -- -v $export_formats -e=$export_options $all_data $test_parameter $param_schema $param_db $param_user_prefix
echo -e "\n$(date '+%F %T') Start packing..."
chmod 755 $EXPORT/*.sh
format=csv
type=all
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=csv
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=csv
type=parlamentarier
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/cartesian_essential_parlamentarier_interessenbindung.csv $EXPORT/cartesian_minimal_parlamentarier_interessenbindung.csv $EXPORT/cartesian_parlamentarier_verguetungstransparenz.csv $EXPORT/cartesian_minimal_parlamentarier_zutrittsberechtigung.csv $EXPORT/cartesian_minimal_parlamentarier_zutrittsberechtigung_mandat.csv
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/cartesian_essential_parlamentarier_interessenbindung.csv.$DOCU_MD $EXPORT/$DOCU/cartesian_minimal_parlamentarier_interessenbindung.csv.$DOCU_MD $EXPORT/$DOCU/cartesian_parlamentarier_verguetungstransparenz.csv.$DOCU_MD $EXPORT/$DOCU/cartesian_minimal_parlamentarier_zutrittsberechtigung.csv.$DOCU_MD $EXPORT/$DOCU/cartesian_minimal_parlamentarier_zutrittsberechtigung_mandat.csv.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=csv
base_name=lobbywatch_export_parlamentarier_transparenzliste
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/cartesian_parlamentarier_verguetungstransparenz.csv
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/cartesian_parlamentarier_verguetungstransparenz.csv.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=sql
base_name=lobbywatch_export
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=graphml
base_name=lobbywatch_export
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=json
type=aggregated
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
if ! $basic_export; then
format=csv
type=neo4j
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.sh
$ZIP_TREE $archive_with_date $EXPORT/node*.$format $EXPORT/relationship*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/node*.$format.$DOCU_MD $EXPORT/$DOCU/relationship*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=json
type=orientdb
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.sh
$ZIP_TREE $archive_with_date $EXPORT/node*.$format $EXPORT/relationship*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/node*.$format.$DOCU_MD $EXPORT/$DOCU/relationship*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=jsonl
type=arangodb
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.sh
$ZIP_TREE $archive_with_date $EXPORT/node*.$type.jsonl $EXPORT/relationship*.$type.jsonl
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/node*.$type.jsonl.$DOCU_MD $EXPORT/$DOCU/relationship*.$type.jsonl.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
# Aggreagted json is basic exports, see above
# format=json
# type=aggregated
format=json
type=all
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=json
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=jsonl
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=xml
type=aggregated
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=xml
type=all
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=xml
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=yaml
type=aggregated
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=yaml
type=all
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=yaml
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=md
type=aggregated
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=md
type=all
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
format=md
type=flat
base_name=lobbywatch_export_$type
echo -e "\nPack $base_name.$format"
archive_with_date=$EXPORT/${DATE_SHORT}_$base_name$export_type.$format.zip
archive=$EXPORT/$base_name$export_type.$format.zip
[ -f "$archive_with_date" ] && rm $archive_with_date
$ZIP $archive_with_date $DOCS $EXPORT/$type*.$format
$ZIP_TREE $archive_with_date $EXPORT/$DOCU/$type*.$format.$DOCU_MD
cp $archive_with_date $archive
$LS $archive_with_date $archive
if $publish; then
cp $archive $publish_dir
fi
fi
if $publish; then
cp $DOCS $publish_dir
echo -e "\nPublished exports to $publish_dir:"
cp $EXPORT_LOG $publish_dir
$LS $publish_dir
# Clean up historised files as they consume a lot of memory
# https://stackoverflow.com/questions/6363441/check-if-a-file-exists-with-wildcard-in-shell-script
ls $EXPORT/202*hist*.*.zip 1> /dev/null 2>&1 && rm $EXPORT/202*hist*.*.zip
find $EXPORT/ -mindepth 1 -mtime +14 -type f -delete
# find . -depth -mindepth 1 -mtime +14 -type f -print
fi
fi
if $isBackupCopy; then
if $publish; then
echo -e "Publish dumps to $publish_dir"
# Copy only the lasted file and remove timestamp form file name
cp "$(ls -dtr1 "$DUMP_DIR"/dbdump_lobbywat_lobbywatch_*.sql.gz | tail -1)" "$publish_dir"/dbdump_full_lobbywat_lobbywatch.sql.gz
cp "$(ls -dtr1 "$DUMP_DIR"/dbdump_data_lobbywat_lobbywatch_*.sql.gz | tail -1)" "$publish_dir"/dbdump_data_lobbywat_lobbywatch.sql.gz
$LS $publish_dir
fi
fi
END_OVERALL=$(date +%s)
DIFF=$(($END_OVERALL - $START_OVERALL))
echo -e "\n$(date '+%F %T')" "Overall elapsed:" $(convertsecs $DIFF) "(${DIFF}s)"
echo -e "\n$(date '+%F %T')" "Overall elapsed:" $(convertsecs $DIFF) "(${DIFF}s)" >>$EXPORT_LOG
quit