Skip to content

Commit 089687d

Browse files
committed
Add DEBUG_ statements
1 parent c88fbac commit 089687d

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

install/assets/functions/10-db-backup

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/command/with-contenv bash
22

33
bootstrap_filesystem() {
4+
if var_true "${DEBUG_BOOTSTRAP_FILESYSTEM}" ; then debug on; fi
45
if [ ! -d "${backup_job_filesystem_path}" ]; then
56
mkdir -p "${backup_job_filesystem_path}"
67
fi
@@ -24,9 +25,11 @@ bootstrap_filesystem() {
2425
mkdir -p "${TEMP_PATH}"
2526
fi
2627
if [ "$(stat -c %U "${TEMP_PATH}")" != "dbbackup" ] ; then chown -R dbbackup:dbbackup "${TEMP_PATH}" ; fi
28+
if var_true "${DEBUG_BOOTSTRAP_FILESYSTEM}" ; then debug off; fi
2729
}
2830

2931
bootstrap_variables() {
32+
if var_true "${DEBUG_BOOTSTRAP_VARIABLES}" ; then debug on; fi
3033
backup_init() {
3134
backup_instance_number=${1}
3235
backup_instance_vars=$(mktemp)
@@ -370,9 +373,12 @@ bootstrap_variables() {
370373
parse_variables) parse_variables "$2" ;;
371374
upgrade ) upgrade_lonely_variables "$2" ;;
372375
esac
376+
377+
if var_true "${DEBUG_BOOTSTRAP_VARIABLES}" ; then debug off; fi
373378
}
374379

375380
backup_couch() {
381+
if var_true "${DEBUG_BACKUP_COUCH}" ; then debug on; fi
376382
prepare_dbbackup
377383
backup_job_filename=couch_${backup_job_db_name}_${backup_job_db_host#*//}_${now}.txt
378384
backup_job_filename_base=couch_${backup_job_db_name}_${backup_job_db_host#*//}
@@ -388,9 +394,11 @@ backup_couch() {
388394
move_dbbackup
389395
check_exit_code move "${backup_job_filename}"
390396
post_dbbackup ${backup_job_db_name}
397+
if var_true "${DEBUG_BACKUP_COUCH}" ; then debug off; fi
391398
}
392399

393400
backup_influx() {
401+
if var_true "${DEBUG_BACKUP_INFLUX}" ; then debug on; fi
394402
if [ "${backup_job_db_name,,}" = "all" ] ; then
395403
write_log debug "Preparing to back up everything"
396404
db_names=justbackupeverything
@@ -447,9 +455,11 @@ backup_influx() {
447455
done
448456
;;
449457
esac
458+
if var_true "${DEBUG_BACKUP_INFLUX}" ; then debug off; fi
450459
}
451460

452461
backup_mongo() {
462+
if var_true "${DEBUG_BACKUP_MONGO}" ; then debug on; fi
453463
prepare_dbbackup
454464
if [ "${backup_job_compression,,}" = "none" ] ; then
455465
backup_job_filename=${dbtype}_${backup_job_db_name,,}_${backup_job_db_host,,}_${now}.archive
@@ -476,9 +486,11 @@ backup_mongo() {
476486
move_dbbackup
477487
check_exit_code move "${backup_job_filename}"
478488
post_dbbackup "${backup_job_db_name}"
489+
if var_true "${DEBUG_BACKUP_MONGO}" ; then debug off; fi
479490
}
480491

481492
backup_mssql() {
493+
if var_true "${DEBUG_BACKUP_MSSQL}" ; then debug on; fi
482494
case "${backup_job_mssql_mode,,}" in
483495
db|database )
484496
prepare_dbbackup
@@ -521,9 +533,11 @@ backup_mssql() {
521533
post_dbbackup "${backup_job_db_name}"
522534
;;
523535
esac
536+
if var_true "${DEBUG_BACKUP_MSSQL}" ; then debug off; fi
524537
}
525538

526539
backup_mysql() {
540+
if var_true "${DEBUG_BACKUP_MYSQL}" ; then debug on; fi
527541
if var_true "${backup_job_mysql_events}" ; then
528542
events="--events"
529543
fi
@@ -586,9 +600,11 @@ backup_mysql() {
586600
check_exit_code move "${backup_job_filename}"
587601
post_dbbackup all
588602
fi
603+
if var_true "${DEBUG_BACKUP_MYSQL}" ; then debug off; fi
589604
}
590605

591606
backup_pgsql() {
607+
if var_true "${DEBUG_BACKUP_PGSQL}" ; then debug on; fi
592608
backup_pgsql_globals() {
593609
prepare_dbbackup
594610
backup_job_filename=pgsql_globals_${backup_job_db_host,,}_${now}.sql
@@ -678,9 +694,11 @@ backup_pgsql() {
678694
post_dbbackup all
679695
if var_true "${_postgres_backup_globals}" ; then backup_pgsql_globals; fi
680696
fi
697+
if var_true "${DEBUG_BACKUP_PGSQL}" ; then debug on; fi
681698
}
682699

683700
backup_redis() {
701+
if var_true "${DEBUG_BACKUP_REDIS}" ; then debug on; fi
684702
prepare_dbbackup
685703
write_log notice "Dumping Redis - Flushing Redis Cache First"
686704
backup_job_filename=redis_all_${backup_job_db_host,,}_${now}.rdb
@@ -711,9 +729,11 @@ backup_redis() {
711729
move_dbbackup
712730
check_exit_code move "${backup_job_filename}"
713731
post_dbbackup all
732+
if var_true "${DEBUG_BACKUP_REDIS}" ; then debug off; fi
714733
}
715734

716735
backup_sqlite3() {
736+
if var_true "${DEBUG_BACKUP_SQLITE3}" ; then debug on; fi
717737
prepare_dbbackup
718738
db=$(basename "${backup_job_db_host}")
719739
db="${db%.*}"
@@ -732,10 +752,12 @@ backup_sqlite3() {
732752
move_dbbackup
733753
check_exit_code move "${backup_job_filename}"
734754
post_dbbackup "${db}"
755+
if var_true "${DEBUG_BACKUP_SQLITE3}" ; then debug off; fi
735756
}
736757

737758
check_availability() {
738-
### Set the Database Type
759+
if var_true "${DEBUG_CHECK_AVAILABILITY}" ; then debug on; fi
760+
### Set the Database Type
739761
if var_false "${backup_job_skip_availability_check}" ; then
740762
case "${dbtype}" in
741763
"couch" )
@@ -834,9 +856,11 @@ check_availability() {
834856
;;
835857
esac
836858
fi
859+
if var_true "${DEBUG_CHECK_AVAILABILITY}" ; then debug off; fi
837860
}
838861

839862
check_exit_code() {
863+
if var_true "${DEBUG_CHECK_EXIT_CODE}" ; then debug on; fi
840864
case "${1}" in
841865
backup )
842866
write_log debug "DB Backup exit Code is ${exit_code}"
@@ -875,9 +899,11 @@ check_exit_code() {
875899
esac
876900
;;
877901
esac
902+
if var_true "${DEBUG_CHECK_EXIT_CODE}" ; then debug off; fi
878903
}
879904

880905
cleanup_old_data() {
906+
if var_true "${DEBUG_CLEANUP_OLD_DATA}" ; then debug on; fi
881907
if [ -n "${backup_job_cleanup_time}" ]; then
882908
if [ "${master_exit_code}" != 1 ]; then
883909
case "${backup_job_backup_location,,}" in
@@ -913,9 +939,11 @@ cleanup_old_data() {
913939
write_log error "Skipping Cleaning up old backups because there were errors in backing up"
914940
fi
915941
fi
942+
if var_true "${DEBUG_CLEANUP_OLD_DATA}" ; then debug off; fi
916943
}
917944

918945
compression() {
946+
if var_true "${DEBUG_COMPRESSION}" ; then debug on; fi
919947
if var_false "${backup_job_parallel_compression}" ; then
920948
backup_job_parallel_compression_threads=1
921949
fi
@@ -979,18 +1007,22 @@ compression() {
9791007
fi
9801008
;;
9811009
esac
1010+
if var_true "${DEBUG_COMPRESSION}" ; then debug off; fi
9821011
}
9831012

9841013
create_archive() {
1014+
if var_true "${DEBUG_CREATE_ARCHIVE}" ; then debug on; fi
9851015
if [ "${exit_code}" = "0" ] ; then
9861016
write_log notice "Creating archive file of '${backup_job_filename_dir}' with tar ${compression_string}"
9871017
run_as_user tar cf - "${TEMP_PATH}"/"${backup_job_filename_dir}" | ${dir_compress_cmd} | run_as_user tee "${TEMP_PATH}"/"${backup_job_filename_dir}".tar"${extension}" > /dev/null
9881018
else
9891019
write_log error "Skipping creating archive file because backup did not complete successfully"
9901020
fi
1021+
if var_true "${DEBUG_CREATE_ARCHIVE}" ; then debug off; fi
9911022
}
9921023

9931024
create_schedulers() {
1025+
if var_true "${DEBUG_CREATE_SCHEDULERS}" ; then debug on; fi
9941026
backup() {
9951027
bootstrap_variables upgrade BACKUP
9961028
local backup_instances=$(printenv | sort | grep -c "^DB[0-9]._HOST")
@@ -1033,6 +1065,7 @@ EOF
10331065
case "${1}" in
10341066
backup ) backup ;;
10351067
esac
1068+
if var_true "${DEBUG_CREATE_SCHEDULERS}" ; then debug off; fi
10361069
}
10371070

10381071
ctrl_c() {
@@ -1048,7 +1081,20 @@ db_backup_container_init() {
10481081
touch /tmp/.container/db-backup-backups
10491082
}
10501083

1084+
debug() {
1085+
case "${1}" in
1086+
off)
1087+
DEBUG_MODE=${OLD_DEBUG_MODE}
1088+
;;
1089+
on)
1090+
OLD_DEBUG_MODE=${DEBUG_MODE}
1091+
DEBUG_MODE=TRUE
1092+
;;
1093+
esac
1094+
}
1095+
10511096
file_encryption() {
1097+
if var_true "${DEBUG_FILE_ENCRYPTION}" ; then debug on; fi
10521098
if var_true "${backup_job_encrypt}" ; then
10531099
if [ "${exit_code}" = "0" ] ; then
10541100
print_debug "Encrypting"
@@ -1086,9 +1132,11 @@ EOF
10861132
write_log error "Skipping encryption because backup did not complete successfully"
10871133
fi
10881134
fi
1135+
if var_true "${DEBUG_FILE_ENCRYPTION}" ; then debug off; fi
10891136
}
10901137

10911138
generate_checksum() {
1139+
if var_true "${DEBUG_GENERATE_CHECKSUM}" ; then debug on; fi
10921140
if [ "${exit_code}" = "0" ] ; then
10931141
case "${backup_job_checksum,,}" in
10941142
"md5" )
@@ -1122,9 +1170,11 @@ EOF
11221170
else
11231171
write_log error "Skipping Checksum creation because backup did not complete successfully"
11241172
fi
1173+
if var_true "${DEBUG_GENERATE_CHECKSUM}" ; then debug off; fi
11251174
}
11261175

11271176
notify() {
1177+
if var_true "${DEBUG_NOTIFY}" ; then debug on; fi
11281178
notification_custom() {
11291179
if [ -n "${NOTIFICATION_SCRIPT}" ] ; then
11301180
if var_true "${NOTIFICATION_SCRIPT_SKIP_X_VERIFY}" ; then
@@ -1268,9 +1318,11 @@ EOF
12681318
esac
12691319
done
12701320
fi
1321+
if var_true "${DEBUG_NOTIFY}" ; then debug off; fi
12711322
}
12721323

12731324
move_dbbackup() {
1325+
if var_true "${DEBUG_MOVE_DBBACKUP}" ; then debug on; fi
12741326
if [ "${exit_code}" = "0" ] ; then
12751327
dbbackup_size="$(run_as_user stat -c%s "${TEMP_PATH}"/"${backup_job_filename}")"
12761328
dbbackup_date="$(run_as_user date -r "${TEMP_PATH}"/"${backup_job_filename}" +'%s')"
@@ -1361,6 +1413,7 @@ move_dbbackup() {
13611413
fi
13621414

13631415
run_as_user rm -rf "${TEMP_PATH}"/"${backup_job_filename}"
1416+
if var_true "${DEBUG_MOVE_DBBACKUP}" ; then debug off; fi
13641417
}
13651418

13661419
prepare_dbbackup() {
@@ -1371,6 +1424,7 @@ prepare_dbbackup() {
13711424
}
13721425

13731426
pre_dbbackup() {
1427+
if var_true "${DEBUG_PRE_DBBACKUP}" ; then debug on; fi
13741428
### Pre Script Support
13751429
if [ -n "${backup_job_pre_script}" ] ; then
13761430
if var_true "${backup_job_pre_script_x_verify}" ; then
@@ -1407,9 +1461,11 @@ pre_dbbackup() {
14071461
fi
14081462
done
14091463
fi
1464+
if var_true "${DEBUG_PRE_DBBACKUP}" ; then debug off; fi
14101465
}
14111466

14121467
post_dbbackup() {
1468+
if var_true "${DEBUG_POST_DBBACKUP}" ; then debug on; fi
14131469
dbbackup_finish_time=$(run_as_user date +"%s")
14141470
dbbackup_total_time=$(run_as_user echo $((dbbackup_finish_time-dbbackup_start_time)))
14151471

@@ -1476,9 +1532,11 @@ EOZP
14761532
fi
14771533

14781534
write_log notice "DB Backup for '${1}' time taken: $(echo ${dbbackup_total_time} | awk '{printf "Hours: %d Minutes: %02d Seconds: %02d", $1/3600, ($1/60)%60, $1%60}')"
1535+
if var_true "${DEBUG_POST_DBBACKUP}" ; then debug on; fi
14791536
}
14801537

14811538
process_limiter() {
1539+
if var_true "${DEBUG_PROCESS_LIMITER}" ; then debug on; fi
14821540
while true ; do
14831541
counter=0
14841542
process_amount="$(wc -l /tmp/.container/db-backup-backups | awk '{print $1}')"
@@ -1497,6 +1555,7 @@ process_limiter() {
14971555
break
14981556
fi
14991557
done
1558+
if var_true "${DEBUG_PROCESS_LIMITER}" ; then debug off; fi
15001559
}
15011560

15021561
run_as_user() {
@@ -1545,6 +1604,7 @@ symlink_log () {
15451604
}
15461605

15471606
timer() {
1607+
if var_true "${DEBUG_TIMER}" ; then debug on; fi
15481608
case "${1}" in
15491609
backup)
15501610
case "${2}" in
@@ -1768,9 +1828,11 @@ timer() {
17681828
time_wait=$(( time_future - time_current ))
17691829
;;
17701830
esac
1831+
if var_true "${DEBUG_TIMER}" ; then debug off; fi
17711832
}
17721833

17731834
write_log() {
1835+
if var_true "${DEBUG_WRITE_LOG}" ; then debug on; fi
17741836
output_off
17751837
local _arg_log_level=${1}
17761838
shift 1
@@ -1815,4 +1877,5 @@ write_log() {
18151877

18161878
print_${_arg_log_level} "${_arg_log_message}"
18171879
output_on
1880+
if var_true "${DEBUG_WRITE_LOG}" ; then debug off; fi
18181881
}

0 commit comments

Comments
 (0)