Skip to content

Commit 6e4dc49

Browse files
1 parent 9b1acc9 commit 6e4dc49

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

automysqlbackup

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ load_default_config() {
6666
CONFIG_rotation_monthly=150
6767
CONFIG_mysql_dump_port=3306
6868
CONFIG_mysql_dump_usessl='yes'
69+
CONFIG_mysql_dump_encrypted_login='no'
70+
CONFIG_mysql_dump_login_path=''
6971
CONFIG_mysql_dump_username='root'
7072
CONFIG_mysql_dump_password=''
7173
CONFIG_mysql_dump_host='localhost'
@@ -436,6 +438,13 @@ backup_local_files () {
436438
# @args: (none)
437439
# @deps: load_default_config
438440
parse_configuration () {
441+
# Authentification per login-path or user/pass // available as of MySQL 5.6.6: http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html
442+
if [[ "${CONFIG_mysql_dump_encrypted_login}" = "yes" ]]; then
443+
authentication=" --login-path="${CONFIG_mysql_dump_login_path}" "
444+
else
445+
authentication=" --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "
446+
fi
447+
439448
# OPT string for use with mysqldump ( see man mysqldump )
440449
opt=( '--quote-names' '--opt' )
441450

@@ -514,7 +523,7 @@ parse_configuration () {
514523
db=${i%.*}
515524
table=${i#"$db".}
516525
r='\*'; [[ "$i" =~ $r ]] || { tmp[z++]="$i"; continue; }
517-
while read -r; do tmp[z++]="${db}.${REPLY}"; done < <(mysql --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${mysql_opt[@]}" --batch --skip-column-names -e "select table_name from information_schema.tables where table_schema='${db}' and table_name like '${table//\*/%}';")
526+
while read -r; do tmp[z++]="${db}.${REPLY}"; done < <(mysql ${authentication} "${mysql_opt[@]}" --batch --skip-column-names -e "select table_name from information_schema.tables where table_schema='${db}' and table_name like '${table//\*/%}';")
518527
done
519528
for l in "${tmp[@]}"; do echo "exclude $l";done
520529
CONFIG_table_exclude=("${tmp[@]}")
@@ -535,28 +544,28 @@ dbstatus() {
535544
if (( $CONFIG_dryrun )); then
536545
case "${CONFIG_mysql_dump_compression}" in
537546
'gzip')
538-
echo "dry-running: mysqlshow --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_dbstatus[@]} | gzip_compression > ${1}${suffix}";
547+
echo "dry-running: mysqlshow ${authentication} ${opt_dbstatus[@]} | gzip_compression > ${1}${suffix}";
539548
;;
540549
'bzip2')
541-
echo "dry-running: mysqlshow --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_dbstatus[@]} | bzip2_compression > ${1}${suffix}";
550+
echo "dry-running: mysqlshow ${authentication} ${opt_dbstatus[@]} | bzip2_compression > ${1}${suffix}";
542551
;;
543552
*)
544-
echo "dry-running: mysqlshow --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_dbstatus[@]} > ${1}${suffix}";
553+
echo "dry-running: mysqlshow ${authentication} ${opt_dbstatus[@]} > ${1}${suffix}";
545554
;;
546555
esac
547556
return 0;
548557
else
549558
case "${CONFIG_mysql_dump_compression}" in
550559
'gzip')
551-
mysqlshow --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_dbstatus[@]}" | gzip_compression > "${1}${suffix}";
560+
mysqlshow ${authentication} "${opt_dbstatus[@]}" | gzip_compression > "${1}${suffix}";
552561
return $?
553562
;;
554563
'bzip2')
555-
mysqlshow --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_dbstatus[@]}" | bzip2_compression > "${1}${suffix}";
564+
mysqlshow ${authentication} "${opt_dbstatus[@]}" | bzip2_compression > "${1}${suffix}";
556565
return $?
557566
;;
558567
*)
559-
mysqlshow --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_dbstatus[@]}" > "${1}${suffix}";
568+
mysqlshow ${authentication} "${opt_dbstatus[@]}" > "${1}${suffix}";
560569
return $?
561570
;;
562571
esac
@@ -571,28 +580,28 @@ fullschema () {
571580
if (( $CONFIG_dryrun )); then
572581
case "${CONFIG_mysql_dump_compression}" in
573582
'gzip')
574-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_fullschema[@]} | gzip_compression > ${1}${suffix}";
583+
echo "dry-running: mysqldump ${authentication} ${opt_fullschema[@]} | gzip_compression > ${1}${suffix}";
575584
;;
576585
'bzip2')
577-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_fullschema[@]} | bzip2_compression > ${1}${suffix}";
586+
echo "dry-running: mysqldump ${authentication} ${opt_fullschema[@]} | bzip2_compression > ${1}${suffix}";
578587
;;
579588
*)
580-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt_fullschema[@]} > ${1}${suffix}";
589+
echo "dry-running: mysqldump ${authentication} ${opt_fullschema[@]} > ${1}${suffix}";
581590
;;
582591
esac
583592
return 0;
584593
else
585594
case "${CONFIG_mysql_dump_compression}" in
586595
'gzip')
587-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_fullschema[@]}" | gzip_compression > "${1}${suffix}";
596+
mysqldump ${authentication} "${opt_fullschema[@]}" | gzip_compression > "${1}${suffix}";
588597
return $?
589598
;;
590599
'bzip2')
591-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_fullschema[@]}" | bzip2_compression > "${1}${suffix}";
600+
mysqldump ${authentication} "${opt_fullschema[@]}" | bzip2_compression > "${1}${suffix}";
592601
return $?
593602
;;
594603
*)
595-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt_fullschema[@]}" > "${1}${suffix}";
604+
mysqldump ${authentication} "${opt_fullschema[@]}" > "${1}${suffix}";
596605
return $?
597606
;;
598607
esac
@@ -710,13 +719,13 @@ process_dbs() {
710719
uid="${uid:-8:8}"
711720
case "${CONFIG_mysql_dump_compression}" in
712721
'gzip')
713-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" | gzip_compression > "$cfname";
722+
mysqldump ${authentication} "${opt[@]}" "$@" | gzip_compression > "$cfname";
714723
;;
715724
'bzip2')
716-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" | bzip2_compression > "$cfname";
725+
mysqldump ${authentication} "${opt[@]}" "$@" | bzip2_compression > "$cfname";
717726
;;
718727
*)
719-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" > "$cfname";
728+
mysqldump ${authentication} "${opt[@]}" "$@" > "$cfname";
720729
;;
721730
esac
722731
add_manifest_entry "$manifest_file" "$cfname" "$pid" "$db" && parse_manifest "$manifest_file" && cp -al "$cfname" "${CONFIG_backup_dir}"/latest/ && echo "Generated master backup $cfname" && return 0 || return 1
@@ -729,29 +738,29 @@ process_dbs() {
729738
case "${CONFIG_mysql_dump_compression}" in
730739
'gzip')
731740
if (( $filename_flags & $filename_flag_gz )); then
732-
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | gzip_compression > "$cfname";
741+
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") | gzip_compression > "$cfname";
733742
elif (( $filename_flags & $filename_flag_bz2 )); then
734-
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | gzip_compression > "$cfname";
743+
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") | gzip_compression > "$cfname";
735744
else
736-
diff "${manifest_latest_master_entry[0]}" <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | gzip_compression > "$cfname";
745+
diff "${manifest_latest_master_entry[0]}" <(mysqldump ${authentication} "${opt[@]}" "$@") | gzip_compression > "$cfname";
737746
fi
738747
;;
739748
'bzip2')
740749
if (( $filename_flags & $filename_flag_gz )); then
741-
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | bzip2_compression > "$cfname";
750+
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") | bzip2_compression > "$cfname";
742751
elif (( $filename_flags & $filename_flag_bz2 )); then
743-
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | bzip2_compression > "$cfname";
752+
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") | bzip2_compression > "$cfname";
744753
else
745-
diff "${manifest_latest_master_entry[0]}" <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") | bzip2_compression > "$cfname";
754+
diff "${manifest_latest_master_entry[0]}" <(mysqldump ${authentication} "${opt[@]}" "$@") | bzip2_compression > "$cfname";
746755
fi
747756
;;
748757
*)
749758
if (( $filename_flags & $filename_flag_gz )); then
750-
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") > "$cfname";
759+
diff <(gzip_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") > "$cfname";
751760
elif (( $filename_flags & $filename_flag_bz2 )); then
752-
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") > "$cfname";
761+
diff <(bzip2_compression -dc "${manifest_latest_master_entry[0]}") <(mysqldump ${authentication} "${opt[@]}" "$@") > "$cfname";
753762
else
754-
diff "${manifest_latest_master_entry[0]}" <(mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@") > "$cfname";
763+
diff "${manifest_latest_master_entry[0]}" <(mysqldump ${authentication} "${opt[@]}" "$@") > "$cfname";
755764
fi
756765
;;
757766
esac
@@ -765,28 +774,28 @@ process_dbs() {
765774
if (( $CONFIG_dryrun )); then
766775
case "${CONFIG_mysql_dump_compression}" in
767776
'gzip')
768-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt[@]} $@ | gzip_compression > ${cfname}"
777+
echo "dry-running: mysqldump ${authentication} ${opt[@]} $@ | gzip_compression > ${cfname}"
769778
;;
770779
'bzip2')
771-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt[@]} $@ | bzip2_compression > ${cfname}"
780+
echo "dry-running: mysqldump ${authentication} ${opt[@]} $@ | bzip2_compression > ${cfname}"
772781
;;
773782
*)
774-
echo "dry-running: mysqldump --user=${CONFIG_mysql_dump_username} --password=${CONFIG_mysql_dump_password} --host=${CONFIG_mysql_dump_host} ${opt[@]} $@ > ${cfname}"
783+
echo "dry-running: mysqldump ${authentication} ${opt[@]} $@ > ${cfname}"
775784
;;
776785
esac
777786
return 0;
778787
else
779788
case "${CONFIG_mysql_dump_compression}" in
780789
'gzip')
781-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" | gzip_compression > "${cfname}"
790+
mysqldump ${authentication} "${opt[@]}" "$@" | gzip_compression > "${cfname}"
782791
ret=$?
783792
;;
784793
'bzip2')
785-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" | bzip2_compression > "${cfname}"
794+
mysqldump ${authentication} "${opt[@]}" "$@" | bzip2_compression > "${cfname}"
786795
ret=$?
787796
;;
788797
*)
789-
mysqldump --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${opt[@]}" "$@" > "${cfname}"
798+
mysqldump ${authentication} "${opt[@]}" "$@" > "${cfname}"
790799
ret=$?
791800
;;
792801
esac
@@ -1057,13 +1066,13 @@ check_dependencies () {
10571066
#
10581067
parse_databases() {
10591068
# bash 4.x version
1060-
#mapfile -t alldbnames < <(mysql --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" --batch --skip-column-names -e "show databases")
1069+
#mapfile -t alldbnames < <(mysql ${authentication} --batch --skip-column-names -e "show databases")
10611070
alldbnames=()
10621071

10631072
printf "# Parsing databases ... "
10641073
# bash 3.0
10651074
local i;i=0;
1066-
while read -r; do alldbnames[i++]="$REPLY"; done < <(mysql --user="${CONFIG_mysql_dump_username}" --password="${CONFIG_mysql_dump_password}" --host="${CONFIG_mysql_dump_host}" "${mysql_opt[@]}" --batch --skip-column-names -e "show databases")
1075+
while read -r; do alldbnames[i++]="$REPLY"; done < <(mysql ${authentication} "${mysql_opt[@]}" --batch --skip-column-names -e "show databases")
10671076
unset i
10681077

10691078
# mkfifo foo || exit; trap 'rm -f foo' EXIT

automysqlbackup.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414

1515
# Basic Settings
1616

17+
# available as of MySQL 5.6.6 you can use stored encrypted authentication credentials
18+
# see: http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html
19+
20+
# use encrypted authentication credentials
21+
#CONFIG_mysql_dump_encrypted_login='no'
22+
23+
# Login path name
24+
#CONFIG_mysql_dump_login_path='local'
25+
1726
# Username to access the MySQL server e.g. dbuser
1827
#CONFIG_mysql_dump_username='root'
1928

0 commit comments

Comments
 (0)