Skip to content

Commit 94e9881

Browse files
committed
Release 3.9.6 - See CHANGELOG.md
1 parent 4253836 commit 94e9881

File tree

3 files changed

+62
-28
lines changed

3 files changed

+62
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.9.6 2023-06-16 <dave at tiredofit dot ca>
2+
3+
### Changed
4+
- Resolve issues introduced with 3.9.3. Split exit codes to be specific for backing up and moving. Uses paremter $11 for post backup scripts
5+
6+
17
## 3.9.5 2023-06-13 <dave at tiredofit dot ca>
28

39
### Changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,18 @@ $ cat post-script.sh
323323
# #### $8=BACKUP FILENAME (Filename)
324324
# #### $9=BACKUP FILESIZE
325325
# #### $10=HASH (If CHECKSUM enabled)
326+
# #### $11=MOVE_EXIT_CODE
326327

327328
echo "${1} ${2} Backup Completed on ${3} for ${4} on ${5} ending ${6} for a duration of ${7} seconds. Filename: ${8} Size: ${9} bytes MD5: ${10}"
328329
````
329330

330331
## script EXIT_CODE DB_TYPE DB_HOST DB_NAME STARTEPOCH FINISHEPOCH DURATIONEPOCH BACKUP_FILENAME FILESIZE CHECKSUMVALUE
331-
${f} "${exit_code}" "${dbtype}" "${dbhost}" "${dbname}" "${backup_start_timme}" "${backup_finish_time}" "${backup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}"
332+
${f} "${exit_code}" "${dbtype}" "${dbhost}" "${dbname}" "${backup_start_timme}" "${backup_finish_time}" "${backup_total_time}" "${target}" "${FILESIZE}" "${checksum_value}" "${move_exit_code}
332333

333334

334335
Outputs the following on the console:
335336

336-
`0 mysql Backup Completed on example-db for example on 1647370800 ending 1647370920 for a duration of 120 seconds. Filename: mysql_example_example-db_202200315-000000.sql.bz2 Size: 7795 bytes Hash: 952fbaafa30437494fdf3989a662cd40`
337+
`0 mysql Backup Completed on example-db for example on 1647370800 ending 1647370920 for a duration of 120 seconds. Filename: mysql_example_example-db_202200315-000000.sql.bz2 Size: 7795 bytes Hash: 952fbaafa30437494fdf3989a662cd40 0`
337338

338339
If you wish to change the size value from bytes to megabytes set environment variable `SIZE_VALUE=megabytes`
339340

install/assets/functions/10-db-backup

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ backup_couch() {
134134
print_notice "Dumping CouchDB database: '${DB_NAME}' ${compression_string}"
135135
curl -sSL -X GET ${DB_HOST}:${DB_PORT}/${DB_NAME}/_all_docs?include_docs=true ${compress_cmd} | $compress_cmd > "${TEMP_LOCATION}"/"${target}"
136136
exit_code=$?
137-
check_exit_code $target
137+
check_exit_code backup $target
138138
generate_checksum
139139
move_dbbackup
140-
check_exit_code "move backup file"
140+
check_exit_code move $target
141141
post_dbbackup ${DB_NAME}
142142
}
143143

@@ -161,14 +161,14 @@ backup_influx() {
161161
print_notice "Dumping Influx database: '${db}'"
162162
influxd backup ${influx_compression} ${bucket} -portable -host ${DB_HOST}:${DB_PORT} ${EXTRA_OPTS} "${TEMP_LOCATION}"/"${target_dir}"
163163
exit_code=$?
164-
check_exit_code $target_dir
164+
check_exit_code backup $target_dir
165165
print_notice "Creating archive file of '${target_dir}' with tar ${compression_string}"
166166
tar cf - "${TEMP_LOCATION}"/"${target_dir}" | $dir_compress_cmd > "${TEMP_LOCATION}"/"${target_dir}".tar"${extension}"
167167
target=influx_${db}_${DB_HOST#*//}_${now}.tar${extension}
168168
ltarget=influx_${db}_${DB_HOST#*//}
169169
generate_checksum
170170
move_dbbackup
171-
check_exit_code "move backup file"
171+
check_exit_code move $target_dir
172172
post_dbbackup $db
173173
done
174174
;;
@@ -183,13 +183,13 @@ backup_influx() {
183183
print_notice "Dumping Influx2 database: '${db}'"
184184
influx backup --org ${DB_USER} ${bucket} --host ${DB_HOST}:${DB_PORT} --token ${DB_PASS} ${EXTRA_OPTS} --compression none "${TEMP_LOCATION}"/"${target_dir}"
185185
exit_code=$?
186-
check_exit_code $target_dir
186+
check_exit_code backup $target_dir
187187
create_archive
188188
target=influx2_${db}_${DB_HOST#*//}_${now}.tar${extension}
189189
ltarget=influx2_${db}_${DB_HOST#*//}
190190
generate_checksum
191191
move_dbbackup
192-
check_exit_code "move backup file"
192+
check_exit_code move $target_dir
193193
post_dbbackup $db
194194
done
195195
;;
@@ -219,7 +219,7 @@ backup_mongo() {
219219
check_exit_code $target
220220
generate_checksum
221221
move_dbbackup
222-
check_exit_code "move backup file"
222+
check_exit_code move $target
223223
post_dbbackup "${DB_NAME}"
224224
}
225225

@@ -232,10 +232,10 @@ backup_mssql() {
232232
print_notice "Dumping MSSQL database: '${DB_NAME}'"
233233
silent /opt/mssql-tools18/bin/sqlcmd -C -S ${DB_HOST}\,${DB_PORT} -U ${DB_USER} -P ${DB_PASS} -Q "BACKUP DATABASE [${DB_NAME}] TO DISK = N'${TEMP_LOCATION}/${target}' WITH NOFORMAT, NOINIT, NAME = '${DB_NAME}-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
234234
exit_code=$?
235-
check_exit_code $target
235+
check_exit_code backup $target
236236
generate_checksum
237237
move_dbbackup
238-
check_exit_code "move backup file"
238+
check_exit_code move $target
239239
post_dbbackup $DB_NAME
240240
}
241241

@@ -273,10 +273,10 @@ backup_mysql() {
273273
print_notice "Dumping MySQL/MariaDB database: '${db}' ${compression_string}"
274274
mysqldump --max-allowed-packet=${MYSQL_MAX_ALLOWED_PACKET} -h ${DB_HOST} -P ${DB_PORT} -u${DB_USER} ${single_transaction} ${stored_procedures} ${mysql_tls_args} ${EXTRA_OPTS} --databases $db | $compress_cmd > "${TEMP_LOCATION}"/"${target}"
275275
exit_code=$?
276-
check_exit_code $target
276+
check_exit_code backup $target
277277
generate_checksum
278278
move_dbbackup
279-
check_exit_code "move backup file"
279+
check_exit_code move $target
280280
post_dbbackup $db
281281
done
282282
else
@@ -292,7 +292,7 @@ backup_mysql() {
292292
check_exit_code $target
293293
generate_checksum
294294
move_dbbackup
295-
check_exit_code "move backup file"
295+
check_exit_code move $target
296296
post_dbbackup all
297297
fi
298298
}
@@ -326,10 +326,10 @@ backup_pgsql() {
326326
print_notice "Dumping PostgresSQL database: '${db}' ${compression_string}"
327327
pg_dump -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} $db ${EXTRA_OPTS} | $compress_cmd > ${TEMP_LOCATION}/${target}
328328
exit_code=$?
329-
check_exit_code $target
329+
check_exit_code backup $target
330330
generate_checksum
331331
move_dbbackup
332-
check_exit_code "move backup file"
332+
check_exit_code move $target
333333
post_dbbackup $db
334334
done
335335
else
@@ -350,10 +350,10 @@ backup_pgsql() {
350350
done
351351
pg_dumpall -h ${DB_HOST} -U ${DB_USER} -p ${DB_PORT} ${pgexclude_arg} ${EXTRA_OPTS} | $compress_cmd > ${TEMP_LOCATION}/${target}
352352
exit_code=$?
353-
check_exit_code $target
353+
check_exit_code backup $target
354354
generate_checksum
355355
move_dbbackup
356-
check_exit_code "move backup file"
356+
check_exit_code move $target
357357
post_dbbackup all
358358
fi
359359
}
@@ -382,10 +382,10 @@ backup_redis() {
382382
compression
383383
pre_dbbackup all
384384
$compress_cmd "${TEMP_LOCATION}/${target_original}"
385-
check_exit_code $target
385+
check_exit_code backup $target
386386
generate_checksum
387387
move_dbbackup
388-
check_exit_code "move backup file"
388+
check_exit_code move $target
389389
post_dbbackup all
390390
}
391391

@@ -400,11 +400,11 @@ backup_sqlite3() {
400400
print_notice "Dumping sqlite3 database: '${DB_HOST}' ${compression_string}"
401401
silent sqlite3 "${DB_HOST}" ".backup '${TEMP_LOCATION}/backup.sqlite3'"
402402
exit_code=$?
403-
check_exit_code $target
403+
check_exit_code backup $target
404404
cat "${TEMP_LOCATION}"/backup.sqlite3 | ${dir_compress_cmd} > "${TEMP_LOCATION}/${target}"
405405
generate_checksum
406406
move_dbbackup
407-
check_exit_code "move backup file"
407+
check_exit_code move $target
408408
post_dbbackup $db
409409
}
410410

@@ -513,6 +513,32 @@ check_availability() {
513513

514514
check_exit_code() {
515515
print_debug "DB Backup Exit Code is ${exit_code}"
516+
case "${1}" in
517+
backup )
518+
case "${exit_code}" in
519+
0 )
520+
print_info "DB Backup of '${2}' completed successfully"
521+
;;
522+
* )
523+
print_error "DB Backup of '${2}' reported errors"
524+
master_exit_code=1
525+
;;
526+
esac
527+
;;
528+
move )
529+
case "${move_exit_code}" in
530+
0 )
531+
print_debug "Moving of backup '${2}' completed successfully"
532+
;;
533+
* )
534+
print_error "Moving of backup '${1}' reported errors"
535+
master_exit_code=1
536+
;;
537+
esac
538+
;;
539+
esac
540+
541+
516542
case "${exit_code}" in
517543
0 )
518544
print_info "DB Backup of '${1}' completed successfully"
@@ -694,6 +720,7 @@ move_dbbackup() {
694720
mkdir -p "${DB_DUMP_TARGET}"
695721
mv "${TEMP_LOCATION}"/*."${checksum_extension}" "${DB_DUMP_TARGET}"/
696722
mv "${TEMP_LOCATION}"/"${target}" "${DB_DUMP_TARGET}"/"${target}"
723+
move_exit_code=$?
697724
if var_true "${CREATE_LATEST_SYMLINK}" ; then
698725
ln -sf "${DB_DUMP_TARGET}"/"${target}" "${DB_DUMP_TARGET}"/latest-"${ltarget}"
699726
fi
@@ -723,7 +750,7 @@ move_dbbackup() {
723750
[[ ( -n "${S3_HOST}" ) ]] && PARAM_AWS_ENDPOINT_URL=" --endpoint-url ${S3_PROTOCOL}://${S3_HOST}"
724751

725752
silent aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/${target} s3://${S3_BUCKET}/${S3_PATH}/${target} ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
726-
exit_code=$?
753+
move_exit_code=$?
727754
if var_true "${ENABLE_CHECKSUM}" ; then
728755
silent aws ${PARAM_AWS_ENDPOINT_URL} s3 cp ${TEMP_LOCATION}/*.${checksum_extension} s3://${S3_BUCKET}/${S3_PATH}/ ${s3_ssl} ${s3_ca_cert} ${S3_EXTRA_OPTS}
729756
fi
@@ -739,7 +766,7 @@ move_dbbackup() {
739766
mv "${TEMP_LOCATION}"/"${target}" "${DB_DUMP_TARGET}"/"${target}"
740767

741768
silent blobxfer upload --mode file --remote-path ${BLOBXFER_REMOTE_PATH} --local-path ${DB_DUMP_TARGET}
742-
exit_code=$?
769+
move_exit_code=$?
743770

744771
rm -rf "${TEMP_LOCATION}"/*."${checksum_extension}"
745772
rm -rf "${TEMP_LOCATION}"/"${target}"
@@ -816,11 +843,11 @@ post_dbbackup() {
816843
### Post Script Support
817844
if [ -n "${POST_SCRIPT}" ] ; then
818845
if var_true "${POST_SCRIPT_SKIP_X_VERIFY}" ; then
819-
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}"
846+
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}" "${move_exit_code}"
820847
else
821848
if [ -x "${POST_SCRIPT}" ] ; then
822849
print_notice "Found POST_SCRIPT environment variable. Executing '${POST_SCRIPT}"
823-
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}"
850+
eval "${POST_SCRIPT}" "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}" "${move_exit_code}"
824851
else
825852
print_error "Can't execute POST_SCRIPT environment variable '${POST_SCRIPT}' as its filesystem bit is not executible!"
826853
fi
@@ -837,12 +864,12 @@ post_dbbackup() {
837864
if [ -d "${SCRIPT_LOCATION_POST}" ] && dir_notempty "${SCRIPT_LOCATION_POST}" ; then
838865
for f in $(find ${SCRIPT_LOCATION_POST} -name \*.sh -type f); do
839866
if var_true "${POST_SCRIPT_SKIP_X_VERIFY}" ; then
840-
${f} "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}"
867+
${f} "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}" "${move_exit_code}"
841868
else
842869
if [ -x "${f}" ] ; then
843870
print_notice "Executing post backup custom script : '${f}'"
844871
## script EXIT_CODE DB_TYPE DB_HOST DB_NAME STARTEPOCH FINISHEPOCH DURATIONEPOCH BACKUP_FILENAME FILESIZE CHECKSUMVALUE
845-
${f} "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}"
872+
${f} "${exit_code}" "${dbtype}" "${DB_HOST}" "${1}" "${dbbackup_start_time}" "${dbbackup_finish_time}" "${dbbackup_total_time}" "${target}" "${filesize}" "${checksum_value}" "${move_exit_code}"
846873
else
847874
print_error "Can't run post backup custom script: '${f}' as its filesystem bit is not executible!"
848875
fi

0 commit comments

Comments
 (0)