-
Notifications
You must be signed in to change notification settings - Fork 271
/
engine-backup.sh.in
executable file
·2300 lines (2065 loc) · 79 KB
/
engine-backup.sh.in
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# ovirt-engine-backup - oVirt engine backup and restore utility
# Copyright oVirt Authors
# SPDX-License-Identifier: Apache-2.0
#
# Clean the environment, see bz 1172191
[ -z "${BACKUP_ENV_CLEAN}" ] && exec -c env -i PATH="${PATH}" TMPDIR="${TMPDIR}" BACKUP_ENV_CLEAN=1 "$0" "$@"
# Instead of loading prolog here, like the other scripts, we included its
# content here, slightly modified, to allow it to work without engine
# config file.
export ENGINE_DEFAULTS="${ENGINE_DEFAULTS:-@ENGINE_DEFAULTS@}"
export ENGINE_VARS="${ENGINE_VARS:-@ENGINE_VARS@}"
export ENGINE_BACKUP_DEFAULT_DIR="${ENGINE_BACKUP_DEFAULT_DIR:-@ENGINE_BACKUP_DEFAULT_DIR@}"
export ENGINE_BACKUP_LOG_DEFAULT_DIR="${ENGINE_BACKUP_LOG_DEFAULT_DIR:-@ENGINE_BACKUP_LOG_DEFAULT_DIR@}"
PACKAGE_NAME="@PACKAGE_NAME@"
PACKAGE_VERSION="@PACKAGE_VERSION@"
DISPLAY_VERSION="@DISPLAY_VERSION@"
ENGINE_USR="@ENGINE_USR@"
die() {
local m="$1"
echo "FATAL: ${m}" >&2
exit 1
}
load_config() {
for f in \
"${ENGINE_DEFAULTS}" \
"${ENGINE_VARS}" \
$([ -d "${ENGINE_VARS}.d" ] && find "${ENGINE_VARS}.d" -name '*.conf' | sort) \
; do
[ -r "${f}" ] && . "${f}"
done
}
source_d() {
local stage="$1"
local my_cfg_dir="/etc/ovirt-engine-backup/engine-backup-${stage}.d"
for f in \
$([ -d "${my_cfg_dir}" ] && find "${my_cfg_dir}" -name '*.sh' | sort) \
; do
[ -r "${f}" ] && . "${f}"
done
}
source_d init
my_load_config() {
load_config
DWH_CONFIG=/etc/ovirt-engine-dwh/ovirt-engine-dwhd.conf
for f in "${DWH_CONFIG}" "${DWH_CONFIG}".d/*.conf; do
[ -e "${f}" ] && . "${f}"
done
load_branding
source_d config
}
get_java_props() {
python@PY_VERSION@ -c "
# Copied from otopi:src/otopi/__init__.py
import sys
def _pythonModulesCompat():
\"\"\"Rename modules to match python3 names.\"\"\"
if sys.version_info[0] < 3:
import ConfigParser
sys.modules['configparser'] = ConfigParser
_pythonModulesCompat()
import configparser
import io
import os
props_file = sys.argv[1]
params = sys.argv[1:]
config = configparser.ConfigParser()
def escape(s, chars):
ret = ''
for c in s:
if c in chars:
ret += '\\\\'
ret += c
return ret
config.optionxform = str
with io.open(props_file, mode='r', encoding='utf-8') as f:
config.readfp(
io.StringIO(
'[default]\n' + f.read()
)
)
for i in range(1, len(params)-1, 2):
s = params[i]
t = params[i+1]
try:
v = config.get('default', t)
print ('%s=\"%s\"' % (s, escape(v, '\"\\\\\$')))
except configparser.NoOptionError:
pass
" "$@"
}
engine_setup_service_enabled() {
otopi-config-query match \
--key "$1" \
--value bool:True \
--file /etc/ovirt-engine-setup.conf
}
engine_enabled() {
engine_setup_service_enabled "OVESETUP_ENGINE_CORE/enable"
}
dwh_enabled() {
engine_setup_service_enabled "OVESETUP_DWH_CORE/enable"
}
cinderlib_enabled() {
engine_setup_service_enabled "OVESETUP_CL_DB/enable"
}
keycloak_enabled() {
engine_setup_service_enabled "OVESETUP_CONFIG/keycloakEnable"
}
grafana_enabled() {
engine_setup_service_enabled "OVESETUP_GRAFANA_CORE/enable"
}
load_branding() {
for f in /etc/ovirt-engine/branding/*/branding-external-resources.properties; do
if [ -e "${f}" ]; then
eval $(get_java_props \
"${f}" \
HELP_URL obrand.common.enginebackup.help_url
)
fi
done
}
# Globals
BACKUP_PATHS="/etc/ovirt-engine
/etc/ovirt-engine-dwh
/etc/ovirt-provider-ovn/conf.d
/etc/ovirt-provider-ovn/logger.conf
/etc/ovirt-vmconsole
/etc/pki/ovirt-engine
/etc/pki/ovirt-vmconsole
/etc/ovirt-engine-setup.conf.d
/etc/httpd/conf.d/internalsso-openidc.conf
/etc/httpd/conf.d/ovirt-engine-grafana-proxy.conf
/etc/httpd/conf.d/ovirt-engine-root-redirect.conf
/etc/httpd/conf.d/ssl.conf
/etc/httpd/conf.d/z-ovirt-engine-proxy.conf
/etc/httpd/conf.d/z-ovirt-engine-keycloak-proxy.conf
/etc/httpd/http.keytab
/etc/httpd/conf.d/ovirt-sso.conf
/etc/yum/pluginconf.d/versionlock.list
/etc/dnf/plugins/versionlock.list
/etc/firewalld/services/ovirt-https.xml
/etc/firewalld/services/ovirt-http.xml
/etc/firewalld/services/ovirt-postgres.xml
/etc/firewalld/services/ovirt-provider-ovn.xml
/etc/firewalld/services/ovn-central-firewall-service.xml
/var/lib/openvswitch
/etc/grafana"
# Add /var/lib/ovirt-engine except a few
VAR_LIB_OVIRT_ENGINE_EXCLUSIONS="/var/lib/ovirt-engine/backups
/var/lib/ovirt-engine/jboss_runtime
/var/lib/ovirt-engine/ansible-runner-service.log
/var/lib/ovirt-engine/ansible-runner
/var/lib/ovirt-engine/.ansible"
for p in /var/lib/ovirt-engine/*; do
echo "${VAR_LIB_OVIRT_ENGINE_EXCLUSIONS}" | grep -q "^${p}\$" || BACKUP_PATHS="${BACKUP_PATHS}
${p}"
done
# Add /var/lib/grafana except its db, which is backed up separately
VAR_LIB_GRAFANA_EXCLUSIONS="/var/lib/grafana/grafana.db"
for p in /var/lib/grafana/*; do
echo "${VAR_LIB_GRAFANA_EXCLUSIONS}" | grep -q "^${p}\$" || BACKUP_PATHS="${BACKUP_PATHS}
${p}"
done
HE_CLEANER="${ENGINE_USR}/setup/dbutils/hecleaner.sh"
ENGINE_TABLES_TO_CLEAN_ON_RESTORE="async_tasks
async_tasks_entities
business_entity_snapshot
command_entities
job
step"
MYPGPASS=""
TEMP_FOLDER=""
FILE=""
DB_BACKUP_FILE_NAME="engine_backup.db"
DWHDB_BACKUP_FILE_NAME="dwh_backup.db"
CINDERLIBDB_BACKUP_FILE_NAME="cinderlib_backup.db"
GRAFANA_BACKUP_FILE_NAME="grafana.db"
KEYCLOAKDB_BACKUP_FILE_NAME="keycloak_backup.db"
PACKAGE_VERSION_FILENAME="version"
OS_VERSION_FILENAME="os_version"
FAILURE_NOTIFIED=
cleanup() {
ec="$?"
source_d cleanup
if [ -n "${ENGINE_DB_USER}" -a "${ec}" = '1' -a "${MODE}" = "backup" -a -z "${FAILURE_NOTIFIED}" ] && [ -n "${LOG}" ]; then
FAILURE_NOTIFIED=1
notify_engine "${ENGINE_DB_USER}" "${ENGINE_DB_HOST}" "${ENGINE_DB_PORT}" "${ENGINE_DB_DATABASE}" -1 "Failed"
fi
if [ "${ec}" = '1' -a -n "${TEMP_FOLDER}" ]; then
local avail=$(df -k --output=avail "${TEMP_FOLDER}" | grep -v Avail)
[ "${avail}" -lt 10000 ] && output "ERROR: Low free space on ${TEMP_FOLDER}: ${avail}KiB"
fi
[ -n "${TEMP_FOLDER}" -a -z "${KEEP_TEMP_FOLDER}" ] && rm -rf "${TEMP_FOLDER}"
}
trap cleanup 0
usage() {
cat << __EOF__
engine-backup: back up and restore ovirt-engine environment
USAGE:
$0 [options]
MODE is one of the following:
backup back up system into FILE(default)
restore restore system from FILE
verify verify FILE
SCOPE is one of the following:
all If MODE=backup: backup everything below.
If MODE=restore: restore everything found in FILE.
files product files only
db Engine database only
dwhdb Data Warehouse database only
cinderlibdb Cinderlib database only
keycloakdb Keycloak database only
grafanadb Grafana database only
The option --scope can be passed more than once, with different scopes.
--file=FILE file to use during backup or restore.
If mode is backup, default to $ENGINE_BACKUP_DEFAULT_DIR/ovirt-engine-backup-YmdHMS.backup
--log=FILE log file to use during backup or restore.
Default to $ENGINE_BACKUP_LOG_DEFAULT_DIR/ovirt-engine-<MODE>-YmdHMS.log
--tmpdir=DIR Set temporary directory parent. See also mktemp(1).
Defaults to \$TMPDIR, if set, otherwise to /tmp.
--archive-compressor=COMPRESSOR
Use COMPRESSOR to compress the backup file, can be one of:
gzip
bzip2
xz
None
--files-compressor=COMPRESSOR compress the product files, same options as --archive-compressor
--keep-temporary-data do not clean up temporary data on restore
--db-compressor=COMPRESSOR compress the Engine database, same options as --archive-compressor
--db-dump-format=FORMAT
Engine database dump format; see pg_dump(1) for details. Can be one of:
plain Note that with this format engine-backup does not allow backing
up or restoring special permissions, by passing to pg_dump the
options '--no-owner --no-privileges'.
custom
--db-restore-jobs=JOBS number of restore jobs for the Engine database,
when using custom dump format and compressor None.
Passed to pg_restore -j. Defaults to 2.
--provision-db create a PostgreSQL database for the Engine on restore
--change-db-credentials activate the following options, to restore
the Engine database using credentials other
than those stored in the backup itself.
If used, existing credentials are ignored.
--db-host=host set Engine database host
--db-port=port set Engine database port
--db-user=user set Engine database user
--db-passfile=file set Engine database password - read from file
--db-password=pass set Engine database password
--db-password set Engine database password - interactively
--db-name=name set Engine database name
--db-secured set a secured connection for the Engine database
--db-secured-validation validate host for Engine database
--dwh-db-compressor=COMPRESSOR compress the Data Warehouse database, same options as --archive-compressor
--dwh-db-dump-format=FORMAT Data Warehouse database dump format, same options as --db-dump-format
--dwh-db-restore-jobs=JOBS for Data Warehouse database, same as --db-restore-jobs
--provision-dwh-db create a PostgreSQL database for Data Warehouse on restore
--change-dwh-db-credentials activate the following options, to restore
the Data Warehouse database using credentials other
than those stored in the backup itself.
If used, existing credentials are ignored.
--dwh-db-host=host set Data Warehouse database host
--dwh-db-port=port set Data Warehouse database port
--dwh-db-user=user set Data Warehouse database user
--dwh-db-passfile=file set Data Warehouse database password - read from file
--dwh-db-password=pass set Data Warehouse database password
--dwh-db-password set Data Warehouse database password - interactively
--dwh-db-name=name set Data Warehouse database name
--dwh-db-secured set a secured connection for the Data Warehouse database
--dwh-db-secured-validation validate host for Data Warehouse database
--cinderlib-db-compressor=COMPRESSOR compress the Cinderlib database, same options as --archive-compressor
--cinderlib-db-dump-format=FORMAT Cinderlib database dump format, same options as --db-dump-format
--cinderlib-db-restore-jobs=JOBS for Cinderlib database, same as --db-restore-jobs
--provision-cinderlib-db create a PostgreSQL database for Cinderlib on restore
--change-cinderlib-db-credentials activate the following options, to restore
the Cinderlib database using credentials other
than those stored in the backup itself.
If used, existing credentials are ignored.
--cinderlib-db-host=host set Cinderlib database host
--cinderlib-db-port=port set Cinderlib database port
--cinderlib-db-user=user set Cinderlib database user
--cinderlib-db-passfile=file set Cinderlib database password - read from file
--cinderlib-db-password=pass set Cinderlib database password
--cinderlib-db-password set Cinderlib database password - interactively
--cinderlib-db-name=name set Cinderlib database name
--cinderlib-db-secured set a secured connection for the Cinderlib database
--cinderlib-db-secured-validation validate host for Cinderlib database
--keycloak-db-compressor=COMPRESSOR compress the Keycloak database, same options as --archive-compressor
--keycloak-db-dump-format=FORMAT Keycloak database dump format, same options as --db-dump-format
--keycloak-db-restore-jobs=JOBS for Keycloak database, same as --db-restore-jobs
--provision-keycloak-db create a PostgreSQL database for Keycloak on restore
--change-keycloak-db-credentials activate the following options, to restore
the Keycloak database using credentials other
than those stored in the backup itself.
If used, existing credentials are ignored.
--keycloak-db-host=host set Keycloak database host
--keycloak-db-port=port set Keycloak database port
--keycloak-db-user=user set Keycloak database user
--keycloak-db-passfile=file set Keycloak database password - read from file
--keycloak-db-password=pass set Keycloak database password
--keycloak-db-password set Keycloak database password - interactively
--keycloak-db-name=name set Keycloak database name
--keycloak-db-secured set a secured connection for the Keycloak database
--keycloak-db-secured-validation validate host for Keycloak database
--no-restore-permissions Affects only the custom dump format. Will pass
to pg_restore '--no-owner --no-privileges'.
--restore-permissions Affects only the custom dump format. Will not
pass to pg_restore '--no-owner --no-privileges'.
Might not work as expected with the --*db-user options.
If provisioning databases, this option will default.
--provision-all-databases on restore, create a PostgreSQL database for all the
databases that were included in the backup
--he-remove-storage-vm Removes the hosted-engine storage domain, all its entities and the hosted-engine VM during restore.
--he-remove-hosts Removes all the hosted-engine hosts during restore.
--fast-restore the default for backup, equivalent to:
--archive-compressor=gzip \\
--files-compressor=xz \\
--db-dump-format=custom \\
--db-compressor=None \\
--dwh-db-dump-format=custom \\
--dwh-db-compressor=None
In addition, you should pass, when restoring:
--db-restore-jobs=N \\
--dwh-db-restore-jobs=N
where 'N' is around 150% of available cpu cores.
--small-size for a small backup file, equivalent to:
--archive-compressor=xz \\
--files-compressor=xz \\
--db-dump-format=plain \\
--db-compressor=xz \\
--dwh-db-dump-format=plain \\
--dwh-db-compressor=xz
--fast-backup for a fast backup, equivalent to:
--archive-compressor=gzip \\
--files-compressor=xz \\
--db-dump-format=custom \\
--db-compressor=None \\
--dwh-db-dump-format=custom \\
--dwh-db-compressor=None
You can use one of --fast-restore, --small-size, --fast-backup, and after that
one of the other compressor/format options for further fine-tuning.
ENVIRONMENT VARIABLES
OVIRT_ENGINE_DATABASE_PASSWORD
Database password as if provided by --db-password=pass option.
OVIRT_DWH_DATABASE_PASSWORD
Database password as if provided by --dwh-db-password=pass option.
OVIRT_CINDERLIB_DATABASE_PASSWORD
Database password as if provided by --cinderlib-db-password=pass option.
OVIRT_KEYCLOAK_DATABASE_PASSWORD
Database password as if provided by --keycloak-db-password=pass option.
Documentation
For more information, please see:
${HELP_URL}
To create a new user/database:
create role <user> with login encrypted password '<password>';
create database <database> owner <user> template template0
encoding 'UTF8' lc_collate 'en_US.UTF-8' lc_ctype 'en_US.UTF-8';
Open access in the firewall/iptables/etc. to the PostgreSQL port,
5432/tcp by default.
Locate pg_hba.conf within your distribution,
common locations are:
- /var/lib/pgsql/data/pg_hba.conf
- /etc/postgresql-*/pg_hba.conf
- /etc/postgresql/*/main/pg_hba.conf
and open access there by adding the following lines:
host <database> <user> 0.0.0.0/0 md5
host <database> <user> ::0/0 md5
Replace <user>, <password>, <database> with appropriate values.
Repeat for Engine, Data Warehouse as required.
__EOF__
return 0
}
HELP_URL="http://www.ovirt.org/Ovirt-engine-backup"
MODE=
DEFAULT_SCOPE=all
SCOPE=
SCOPE_FILES=
SCOPE_ENGINE_DB=
SCOPE_DWH_DB=
SCOPE_CINDERLIB_DB=
SCOPE_KEYCLOAK_DB=
SCOPE_GRAFANA_DB=
KEEP_TEMPORARY_DATA=
ARCHIVE_COMPRESS_OPTION=z
FILES_COMPRESS_OPTION=J
DB_DUMP_COMPRESSOR=
DB_DUMP_FORMAT=custom
DB_RESTORE_JOBS=2
PROVISIONING=
PROVISION_DB=
POSTGRESQL_DEFAULT_PORT=5432
CHANGE_DB_CREDENTIALS=
MY_DB_HOST=
MY_DB_PORT="${POSTGRESQL_DEFAULT_PORT}"
MY_DB_USER=
ORIG_DB_USER=
MY_DB_PASSWORD="${OVIRT_ENGINE_DATABASE_PASSWORD}"
MY_DB_DATABASE=
MY_DB_SECURED=False
MY_DB_SECURED_VALIDATION=False
MY_DB_CREDS=
DWH_DB_DUMP_COMPRESSOR=
DWH_DB_DUMP_FORMAT=custom
DWH_DB_RESTORE_JOBS=2
PROVISION_DWH_DB=
CHANGE_DWH_DB_CREDENTIALS=
MY_DWH_DB_HOST=
MY_DWH_DB_PORT="${POSTGRESQL_DEFAULT_PORT}"
MY_DWH_DB_USER=
ORIG_DWH_DB_USER=
MY_DWH_DB_PASSWORD="${OVIRT_DWH_DATABASE_PASSWORD}"
MY_DWH_DB_DATABASE=
MY_DWH_DB_SECURED=False
MY_DWH_DB_SECURED_VALIDATION=False
MY_DWH_DB_CREDS=
CINDERLIB_DB_DUMP_COMPRESSOR=
CINDERLIB_DB_DUMP_FORMAT=custom
CINDERLIB_DB_RESTORE_JOBS=2
PROVISION_CINDERLIB_DB=
CHANGE_CINDERLIB_DB_CREDENTIALS=
MY_CINDERLIB_DB_HOST=
MY_CINDERLIB_DB_PORT="${POSTGRESQL_DEFAULT_PORT}"
MY_CINDERLIB_DB_USER=
ORIG_CINDERLIB_DB_USER=
MY_CINDERLIB_DB_PASSWORD="${OVIRT_CINDERLIB_DATABASE_PASSWORD}"
MY_CINDERLIB_DB_DATABASE=
MY_CINDERLIB_DB_SECURED=False
MY_CINDERLIB_DB_SECURED_VALIDATION=False
MY_CINDERLIB_DB_CREDS=
KEYCLOAK_DB_DUMP_COMPRESSOR=
KEYCLOAK_DB_DUMP_FORMAT=custom
KEYCLOAK_DB_RESTORE_JOBS=2
PROVISION_KEYCLOAK_DB=
CHANGE_KEYCLOAK_DB_CREDENTIALS=
MY_KEYCLOAK_DB_HOST=
MY_KEYCLOAK_DB_PORT="${POSTGRESQL_DEFAULT_PORT}"
MY_KEYCLOAK_DB_USER=
ORIG_KEYCLOAK_DB_USER=
MY_KEYCLOAK_DB_PASSWORD="${OVIRT_KEYCLOAK_DATABASE_PASSWORD}"
MY_KEYCLOAK_DB_DATABASE=
MY_KEYCLOAK_DB_SECURED=False
MY_KEYCLOAK_DB_SECURED_VALIDATION=False
MY_KEYCLOAK_DB_CREDS=
GRAFANA_DB_FILENAME=/var/lib/grafana/grafana.db
RESTORE_PERMISSIONS=
PROVISION_ALL_DBS=
HE_REMOVE_STORAGE_VM=
HE_REMOVE_HOSTS=
VALID_BACKUP_RESTORE_PAIRS="4.3 4.5
4.4 4.5"
# A newline-separated list of pair. E.g. if we want to allow 4.0->4.1,
#VALID_BACKUP_RESTORE_PAIRS="3.6 4.0
#4.0 4.1"
BACKUP_VERSION=
INSTALLED_VERSION=
EXCLUDED_FILES_ON_RESTORE="etc/ovirt-engine/engine-config/engine-config.properties
etc/ovirt-engine-setup.conf.d/*packaging*
etc/pki/ovirt-engine/cacert.template.in
etc/pki/ovirt-engine/cert.template.in
etc/pki/ovirt-engine/openssl.conf
etc/ovirt-engine/engine.conf.d/20-branding-rhv.conf
etc/ovirt-engine/branding/50-rhv-2.brand
ovirt-engine/engine.conf.d/10-scl-postgres.conf
ovirt-engine-dwh/ovirt-engine-dwhd.conf.d/10-scl-postgres.conf"
# Hashers. Must support:
# - No options, for creation of hash file
# - '-c hashfile --status', for verifying a hash file
# On restore, search for all of them inside the tar, use first found
AVAILABLE_HASHERS="sha256sum md5sum"
# On backup, use this one
HASHER="sha256sum"
# In all cases, the file name containing the hashes is identical to the hasher itself.
source_d defaults
compressor_to_tar_option() {
local res
case "$1" in
gzip) res=z ;;
bzip2) res=j ;;
xz) res=J ;;
None) res= ;;
*) die "invalid compressor '${v}'"
esac
echo "${res}"
}
compressor_to_command() {
local res
case "$1" in
gzip|bzip2|xz) res="$1" ;;
None) res= ;;
*) die "invalid compressor '${v}'"
esac
echo "${res}"
}
parse_dump_format() {
local res
case "$1" in
plain|custom) res="$1" ;;
*) die "invalid dump format '${v}'"
esac
echo "${res}"
}
parse_jobs() {
local res
case "$1" in
''|*[!0-9]*) die "invalid number of jobs" ;;
*) res="$1"
esac
echo "${res}"
}
set_scope() {
local s="$1"
case "${s}" in
all)
SCOPE_FILES=1
SCOPE_ENGINE_DB=1
SCOPE_DWH_DB=1
SCOPE_CINDERLIB_DB=1
SCOPE_KEYCLOAK_DB=1
SCOPE_GRAFANA_DB=1
;;
files)
SCOPE_FILES=1
;;
db)
SCOPE_ENGINE_DB=1
;;
dwhdb)
SCOPE_DWH_DB=1
;;
cinderlibdb)
SCOPE_CINDERLIB_DB=1
;;
keycloakdb)
SCOPE_KEYCLOAK_DB=1
;;
grafanadb)
SCOPE_GRAFANA_DB=1
;;
*) die "invalid scope '${s}'"
esac
if [ -z "${SCOPE}" ]; then
SCOPE="${s}"
else
SCOPE="${SCOPE},${s}"
fi
}
parseArgs() {
local DB_PASSFILE
while [ -n "$1" ]; do
local x="$1"
local v="${x#*=}"
shift
case "${x}" in
--mode=*)
MODE="${v}"
case "${MODE}" in
backup|restore|verify);;
*) die "invalid mode" ;;
esac
;;
--scope=*)
set_scope "${v}"
;;
--file=*)
FILE="${v}"
;;
--log=*)
LOG="${v}"
;;
--tmpdir=*)
TMPDIR="${v}"
;;
--archive-compressor=*)
ARCHIVE_COMPRESS_OPTION=$(compressor_to_tar_option "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--files-compressor=*)
FILES_COMPRESS_OPTION=$(compressor_to_tar_option "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--keep-temporary-data)
KEEP_TEMPORARY_DATA=1
;;
--db-compressor=*)
DB_DUMP_COMPRESSOR=$(compressor_to_command "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--db-dump-format=*)
DB_DUMP_FORMAT=$(parse_dump_format "${v}")
[ $? != 0 ] && die "failed parsing dump format"
;;
--db-restore-jobs=*)
DB_RESTORE_JOBS=$(parse_jobs "${v}")
[ $? != 0 ] && die "failed parsing jobs"
;;
--provision-db)
PROVISION_DB=1
PROVISIONING=1
;;
--change-db-credentials)
CHANGE_DB_CREDENTIALS=1
;;
--db-host=*)
MY_DB_HOST="${v}"
;;
--db-port=*)
MY_DB_PORT="${v}"
;;
--db-user=*)
MY_DB_USER="${v}"
ORIG_DB_USER="${ENGINE_DB_USER}"
;;
--db-passfile=*)
DB_PASSFILE="${v}"
[ -r "${DB_PASSFILE}" ] || \
die "Can not read password file ${DB_PASSFILE}"
read -r MY_DB_PASSWORD < "${DB_PASSFILE}"
;;
--db-password=*)
MY_DB_PASSWORD="${v}"
;;
--db-password)
MY_DB_PASSWORD="$(readdbpassword Engine)" || exit 1
;;
--db-name=*)
MY_DB_DATABASE="${v}"
;;
--db-secured)
MY_DB_SECURED="True"
;;
--db-sec-validation)
MY_DB_SECURED_VALIDATION="True"
;;
--dwh-db-compressor=*)
DWH_DB_DUMP_COMPRESSOR=$(compressor_to_command "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--dwh-db-dump-format=*)
DWH_DB_DUMP_FORMAT=$(parse_dump_format "${v}")
[ $? != 0 ] && die "failed parsing dump format"
;;
--dwh-db-restore-jobs=*)
DWH_DB_RESTORE_JOBS=$(parse_jobs "${v}")
[ $? != 0 ] && die "failed parsing jobs"
;;
--provision-dwh-db)
PROVISION_DWH_DB=1
PROVISIONING=1
;;
--change-dwh-db-credentials)
CHANGE_DWH_DB_CREDENTIALS=1
;;
--dwh-db-host=*)
MY_DWH_DB_HOST="${v}"
;;
--dwh-db-port=*)
MY_DWH_DB_PORT="${v}"
;;
--dwh-db-user=*)
MY_DWH_DB_USER="${v}"
ORIG_DWH_DB_USER="${DWH_DB_USER}"
;;
--dwh-db-passfile=*)
DB_PASSFILE="${v}"
[ -r "${DB_PASSFILE}" ] || \
die "Can not read password file ${DB_PASSFILE}"
read -r MY_DWH_DB_PASSWORD < "${DB_PASSFILE}"
;;
--dwh-db-password=*)
MY_DWH_DB_PASSWORD="${v}"
;;
--dwh-db-password)
MY_DWH_DB_PASSWORD="$(readdbpassword DWH)" || exit 1
;;
--dwh-db-name=*)
MY_DWH_DB_DATABASE="${v}"
;;
--dwh-db-secured)
MY_DWH_DB_SECURED="True"
;;
--dwh-db-sec-validation)
MY_DWH_DB_SECURED_VALIDATION="True"
;;
--cinderlib-db-compressor=*)
CINDERLIB_DB_DUMP_COMPRESSOR=$(compressor_to_command "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--cinderlib-db-dump-format=*)
CINDERLIB_DB_DUMP_FORMAT=$(parse_dump_format "${v}")
[ $? != 0 ] && die "failed parsing dump format"
;;
--cinderlib-db-restore-jobs=*)
CINDERLIB_DB_RESTORE_JOBS=$(parse_jobs "${v}")
[ $? != 0 ] && die "failed parsing jobs"
;;
--provision-cinderlib-db)
PROVISION_CINDERLIB_DB=1
PROVISIONING=1
;;
--change-cinderlib-db-credentials)
CHANGE_CINDERLIB_DB_CREDENTIALS=1
;;
--cinderlib-db-host=*)
MY_CINDERLIB_DB_HOST="${v}"
;;
--cinderlib-db-port=*)
MY_CINDERLIB_DB_PORT="${v}"
;;
--cinderlib-db-user=*)
MY_CINDERLIB_DB_USER="${v}"
ORIG_CINDERLIB_DB_USER="${CINDERLIB_DB_USER}"
;;
--cinderlib-db-passfile=*)
DB_PASSFILE="${v}"
[ -r "${DB_PASSFILE}" ] || \
die "Can not read password file ${DB_PASSFILE}"
read -r MY_CINDERLIB_DB_PASSWORD < "${DB_PASSFILE}"
;;
--cinderlib-db-password=*)
MY_CINDERLIB_DB_PASSWORD="${v}"
;;
--cinderlib-db-password)
MY_CINDERLIB_DB_PASSWORD="$(readdbpassword CINDERLIB)" || exit 1
;;
--cinderlib-db-name=*)
MY_CINDERLIB_DB_DATABASE="${v}"
;;
--cinderlib-db-secured)
MY_CINDERLIB_DB_SECURED="True"
;;
--cinderlib-db-sec-validation)
MY_CINDERLIB_DB_SECURED_VALIDATION="True"
;;
--keycloak-db-compressor=*)
KEYCLOAK_DB_DUMP_COMPRESSOR=$(compressor_to_command "${v}")
[ $? != 0 ] && die "failed parsing compressor"
;;
--keycloak-db-dump-format=*)
KEYCLOAK_DB_DUMP_FORMAT=$(parse_dump_format "${v}")
[ $? != 0 ] && die "failed parsing dump format"
;;
--keycloak-db-restore-jobs=*)
KEYCLOAK_DB_RESTORE_JOBS=$(parse_jobs "${v}")
[ $? != 0 ] && die "failed parsing jobs"
;;
--provision-keycloak-db)
PROVISION_KEYCLOAK_DB=1
PROVISIONING=1
;;
--change-keycloak-db-credentials)
CHANGE_KEYCLOAK_DB_CREDENTIALS=1
;;
--keycloak-db-host=*)
MY_KEYCLOAK_DB_HOST="${v}"
;;
--keycloak-db-port=*)
MY_KEYCLOAK_DB_PORT="${v}"
;;
--keycloak-db-user=*)
MY_KEYCLOAK_DB_USER="${v}"
ORIG_KEYCLOAK_DB_USER="${KEYCLOAK_DB_USER}"
;;
--keycloak-db-passfile=*)
DB_PASSFILE="${v}"
[ -r "${DB_PASSFILE}" ] || \
die "Can not read password file ${DB_PASSFILE}"
read -r MY_KEYCLOAK_DB_PASSWORD < "${DB_PASSFILE}"
;;
--keycloak-db-password=*)
MY_KEYCLOAK_DB_PASSWORD="${v}"
;;
--keycloak-db-password)
MY_KEYCLOAK_DB_PASSWORD="$(readdbpassword KEYCLOAK)" || exit 1
;;
--keycloak-db-name=*)
MY_KEYCLOAK_DB_DATABASE="${v}"
;;
--keycloak-db-secured)
MY_KEYCLOAK_DB_SECURED="True"
;;
--keycloak-db-sec-validation)
MY_KEYCLOAK_DB_SECURED_VALIDATION="True"
;;
--restore-permissions)
RESTORE_PERMISSIONS=1
;;
--no-restore-permissions)
RESTORE_PERMISSIONS=0
;;
--provision-all-databases)
PROVISION_ALL_DBS=1
PROVISIONING=1
;;
--he-remove-storage-vm)
HE_REMOVE_STORAGE_VM=1
;;
--he-remove-hosts)
HE_REMOVE_HOSTS=1
;;
--fast-restore)
ARCHIVE_COMPRESS_OPTION=z
FILES_COMPRESS_OPTION=J
DB_DUMP_FORMAT=custom
DB_DUMP_COMPRESSOR=
DWH_DB_DUMP_FORMAT=custom
DWH_DB_DUMP_COMPRESSOR=
;;
--small-size)
ARCHIVE_COMPRESS_OPTION=J
FILES_COMPRESS_OPTION=J
DB_DUMP_FORMAT=plain
DB_DUMP_COMPRESSOR=xz
DWH_DB_DUMP_FORMAT=plain
DWH_DB_DUMP_COMPRESSOR=xz
;;
--fast-backup)
ARCHIVE_COMPRESS_OPTION=z
FILES_COMPRESS_OPTION=J
DB_DUMP_FORMAT=custom
DB_DUMP_COMPRESSOR=
DWH_DB_DUMP_FORMAT=custom
DWH_DB_DUMP_COMPRESSOR=
;;
--help)
usage
exit 0
;;
*)
die "Unknown option '${x}'. Please see '--help' for details."
;;
esac
done
[ -z "${TMPDIR}" ] && TMPDIR=/tmp
export TMPDIR
if [ -z "${SCOPE}" ]; then
set_scope "${DEFAULT_SCOPE}"
fi
if [ -z "${MODE}" ]; then
MODE=backup
fi
local date_default_opt=$(date +"%Y%m%d%H%M%S")
if [ -z "${FILE}" -a "${MODE}" == "backup" ]; then
FILE="${ENGINE_BACKUP_DEFAULT_DIR}/ovirt-engine-backup-${date_default_opt}.backup"
fi
if [ -z "${LOG}" ]; then
LOG="${ENGINE_BACKUP_LOG_DEFAULT_DIR}/ovirt-engine-$MODE-${date_default_opt}.log"
fi
if [ "${PROVISIONING=}" == "1" ]; then
if [ -z "${RESTORE_PERMISSIONS}" ]; then
RESTORE_PERMISSIONS="1"
fi
fi
}
verifyArgs() {
[ -n "${MODE}" ] || die "--mode=<backup|restore|verify> is missing"
[ -n "${FILE}" ] || die "--file is missing"
[ -n "${LOG}" ] || die "--log is missing"
[ -d "${TMPDIR}" ] || die "Temporary directory ${TMPDIR} is missing or not a directory"
if [ "${FILE}" == "${LOG}" ]; then
die "--file and --log can not be the same"
fi
if [ "${MODE}" == "restore" ] ; then
[ -e "${FILE}" ] || die "${FILE} does not exist"
fi
if [ -n "${HE_REMOVE_STORAGE_VM}" -o -n "${HE_REMOVE_HOSTS}" ] ; then
if [ "${MODE}" != "restore" ] ; then
die "hosted-engine cleaning options work only in restore mode"
fi
fi
if [ -n "${CHANGE_DB_CREDENTIALS}" ]; then
[ -n "${PROVISION_DB}" -o -n "${PROVISION_ALL_DBS}" ] && die "Cannot change credentials if provisioning a database"
[ -n "${MY_DB_HOST}" ] || die "--db-host is missing"
[ -n "${MY_DB_USER}" ] || die "--db-user is missing"
[ -n "${MY_DB_PASSWORD}" ] || \
die "--db-passfile or --db-password is missing"
[ -n "${MY_DB_DATABASE}" ] || die "--db-name is missing"
fi
[ -z "${CHANGE_DB_CREDENTIALS}" -a \
\( \
-n "${MY_DB_HOST}" \
-o -n "${MY_DB_USER}" \
-o -n "${MY_DB_PASSWORD}" \
-o -n "${MY_DB_DATABASE}" \
\) \
] && die "Please use --change-db-credentials to change engine db credentials"
if [ -n "${CHANGE_DWH_DB_CREDENTIALS}" ]; then
[ -n "${PROVISION_DWH_DB}" -o -n "${PROVISION_ALL_DBS}" ] && die "Cannot change credentials if provisioning a database"
[ -n "${MY_DWH_DB_HOST}" ] || die "--dwh-db-host is missing"
[ -n "${MY_DWH_DB_USER}" ] || die "--dwh-db-user is missing"
[ -n "${MY_DWH_DB_PASSWORD}" ] || \
die "--dwh-db-passfile or --dwh-db-password is missing"
[ -n "${MY_DWH_DB_DATABASE}" ] || die "--dwh-db-name is missing"
fi
[ -z "${CHANGE_DWH_DB_CREDENTIALS}" -a \
\( \
-n "${MY_DWH_DB_HOST}" \
-o -n "${MY_DWH_DB_USER}" \
-o -n "${MY_DWH_DB_PASSWORD}" \
-o -n "${MY_DWH_DB_DATABASE}" \
\) \
] && die "Please use --change-dwh-db-credentials to change dwh db credentials"
if [ -n "${CHANGE_CINDERLIB_DB_CREDENTIALS}" ]; then
[ -n "${PROVISION_CINDERLIB_DB}" -o -n "${PROVISION_ALL_DBS}" ] && die "Cannot change credentials if provisioning a database"
[ -n "${MY_CINDERLIB_DB_HOST}" ] || die "--cinderlib-db-host is missing"
[ -n "${MY_CINDERLIB_DB_USER}" ] || die "--cinderlib-db-user is missing"
[ -n "${MY_CINDERLIB_DB_PASSWORD}" ] || \
die "--cinderlib-db-passfile or --cinderlib-db-password is missing"
[ -n "${MY_CINDERLIB_DB_DATABASE}" ] || die "--cinderlib-db-name is missing"
fi
[ -z "${CHANGE_CINDERLIB_DB_CREDENTIALS}" -a \
\( \
-n "${MY_CINDERLIB_DB_HOST}" \
-o -n "${MY_CINDERLIB_DB_USER}" \
-o -n "${MY_CINDERLIB_DB_PASSWORD}" \
-o -n "${MY_CINDERLIB_DB_DATABASE}" \
\) \
] && die "Please use --change-cinderlib-db-credentials to change cinderlib db credentials"
if [ -n "${CHANGE_KEYCLOAK_DB_CREDENTIALS}" ]; then