From aae11dee5bf72412df10baddfb24faddb7fe8c7c Mon Sep 17 00:00:00 2001 From: John Grigutis Date: Thu, 23 Nov 2017 21:09:35 -0500 Subject: [PATCH 1/5] Whitespace cleanup thanks to Atom --- automysqlbackup | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/automysqlbackup b/automysqlbackup index 4024d36..4d2ff37 100755 --- a/automysqlbackup +++ b/automysqlbackup @@ -9,7 +9,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -516,7 +516,7 @@ parse_configuration () { else opt=( "${opt[@]}" '--databases' ) fi - + # if differential backup is active and the specified rotation is smaller than 21 days, set it to 21 days to ensure, that # master backups aren't deleted. if [[ "x$CONFIG_mysql_dump_differential" = "xyes" ]] && (( ${CONFIG_rotation_daily} < 21 )); then @@ -664,7 +664,7 @@ process_dbs() { manifest_file="${CONFIG_backup_dir}/${subfolder}${subsubfolder}/Manifest" fname="${CONFIG_backup_dir}/${subfolder}${subsubfolder}/${prefix}${name}_${datetimestamp}${midfix}${extension}" - (( $CONFIG_debug )) && echo "DEBUG: process_dbs >> Setting manifest file to: ${manifest_file}" + (( $CONFIG_debug )) && echo "DEBUG: process_dbs >> Setting manifest file to: ${manifest_file}" if (( $multipledbs )); then # multiple databases @@ -688,7 +688,7 @@ process_dbs() { # -> generate diff file let "filename_flags=0x00" - + # ## -> get latest differential manifest entry for specified db # if get_latest_manifest_entry_for_db "$db" 1; then # pid="${manifest_entry[2]}" @@ -781,7 +781,7 @@ process_dbs() { ;; esac add_manifest_entry "$manifest_file" "$cfname" "$pid" "$db" && parse_manifest "$manifest_file" && cp -al "$cfname" "${manifest_latest_master_entry[0]}" "${CONFIG_backup_dir}"/latest/ && echo "generated $cfname" && return 0 || return 1 - + fi # <- generate diff filename @@ -818,7 +818,7 @@ process_dbs() { fi fi - + if (( $ret == 0 )); then echo "Rotating $(( ${rotation}/${rotation_divisor} )) ${rotation_string} backups for ${name}" @@ -1039,7 +1039,7 @@ check_dependencies () { else [[ "x$CONFIG_mysql_dump_compression" = 'xbzip2' ]] && dependencies=("${dependencies[@]}" 'bzip2' ) [[ "x$CONFIG_mysql_dump_compression" = 'xgzip' ]] && dependencies=("${dependencies[@]}" 'gzip' ) - fi + fi if [[ "x$CONFIG_mailcontent" = 'xlog' || "x$CONFIG_mailcontent" = 'xquiet' ]]; then dependencies=( "${dependencies[@]}" 'mail' ) @@ -1219,7 +1219,7 @@ parse_manifest() { (( $CONFIG_debug )) && echo "Found multiple entries with the same filename. Removing all but the first-found entry from manifest." # remove all entries with this filename and add a new one based on the values of the item already in the array rm_manifest_entry_by_filename "$1" "${manifest_array[i]}" 1 && add_manifest_entry "$1" "${manifest_array[i]}" "${manifest_array[i+3]}" - continue 2 # the original entry, to which we compared, is already in the manifest_array; no matter if this is resolved or not, we don't + continue 2 # the original entry, to which we compared, is already in the manifest_array; no matter if this is resolved or not, we don't # need to add this entry to the manifest_array elif [[ "x${manifest_array[i+1]}" = "x${line_arr[2]}" ]]; then # found entry with different filename but same md5sum - file copied and renamed?! if [[ ! -s "${line_arr[0]}" ]]; then # empty file - don't start to compare md5sums ... @@ -1228,7 +1228,7 @@ parse_manifest() { (( $CONFIG_debug )) && echo "Found multiple entries with the same md5sum but different filename." (( $CONFIG_debug )) && echo -e ">> fname_manifest:\t${manifest_array[i]}\t${manifest_array[i+1]}\n>> fname_line:\t\t${line_arr[0]}\t${line_arr[2]}" if [[ "x${line_arr[6]}" != "x0" ]]; then - if [[ "x${manifest_array[i+3]}" = "x${line_arr[6]}" ]]; then # parent id is the same; TODO inform user of this predicament and suggest solution + if [[ "x${manifest_array[i+3]}" = "x${line_arr[6]}" ]]; then # parent id is the same; TODO inform user of this predicament and suggest solution manifest_entries_user_action_required=( "${manifest_entries_user_action_required[@]}" "$1" "${manifest_array[i]}" "The file has an identical copy with the same parent id. If you don't know why it exists, it is safe to remove it." ) continue 2 else @@ -1245,7 +1245,7 @@ parse_manifest() { manifest_array[(n-1)*${fields}+i/2]="${line_arr[i]}" #echo "manifest array key $((($n-1)*4+$i/2)) with value ${line_arr[i]}" done - + ((n++)) done < <(sort -t $'\t' -k"1" "$1") (( $CONFIG_debug )) && echo "<<<<<<< # manifest entries: $((${#manifest_array[@]}/$fields))" @@ -1387,7 +1387,7 @@ get_latest_manifest_entry_for_db() { } # @params: manifest_file filename/md5sum/id/rel_id [1(=don't parse manifest after finished)] -# if second parameters +# if second parameters # # lock manifest -> use awk, print all lines that don't have second parameter at the appropriate field -> unlock manifest # param3=0 -> parse manifest @@ -1489,7 +1489,7 @@ extended_select() { echo -e "$i) [ ]\t${list[i]}" fi done - + echo -e "$i)\tDONE" done_id=$i @@ -1640,7 +1640,7 @@ extended_select() { for i in "${selection[@]}"; do [[ "x$i" != "x$done_id" ]] && { extended_select_return=("${extended_select_return[@]}" "${list[i]}"); extended_select_return_id=("${extended_select_return_id[@]}" "$i"); } done - + } # END _functions @@ -1666,7 +1666,7 @@ method_backup () { # load mysql commands mysql_commands - + (( $CONFIG_dryrun )) && { echo "NOTE: We are dry-running. That means, that the script just shows you what it would do, if it were operating normally." echo "THE PRINTED COMMANDS CAN'T BE COPIED AND EXECUTED IF THERE ARE SPECIAL CHARACTERS, SPACES, ETC. IN THERE THAT WOULD NEED TO BE PROPERLY QUOTED IN ORDER TO WORK. THESE WERE CORRECTLY QUOTED FOR THE OUTPUT COMMAND, BUT CAN'T BE SEEN NOW." @@ -1675,7 +1675,7 @@ method_backup () { export LC_ALL=C PROGNAME=`basename $0` - PATH=${PATH}:/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin + PATH=${PATH}:/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin version=3.0 fields=5 # manifest fields @@ -1721,7 +1721,7 @@ method_backup () { echo "======================================================================" echo "AutoMySQLBackup version ${version}" echo "http://sourceforge.net/projects/automysqlbackup/" - echo + echo echo "Backup of Database Server - ${CONFIG_mysql_dump_host_friendly:-$CONFIG_mysql_dump_host}" ( IFS=,; echo "Databases - ${CONFIG_db_names[*]}" ) ( IFS=,; echo "Databases (monthly) - ${CONFIG_db_month_names[*]}" ) @@ -1746,7 +1746,7 @@ method_backup () { echo "Backup local files. Doing this weekly on CONFIG_do_weekly." echo backup_local_files "${CONFIG_backup_dir}/backup_local_files/bcf_weekly_${datetimestamp}_${date_weekno}.tar" - tmp_flags=$?; var=; + tmp_flags=$?; var=; if (( $? == 0 )); then echo "success!" backupfiles=( "${backupfiles[@]}" "${CONFIG_backup_dir}/backup_local_files/bcf_weekly_${datetimestamp}_${date_weekno}.tar" ) @@ -1820,7 +1820,7 @@ method_backup () { echo echo "======================================================================" echo - + fi # <- dump full schema @@ -1884,7 +1884,7 @@ method_backup () { echo echo "======================================================================" echo - + fi # <- dump status @@ -2036,10 +2036,10 @@ method_list_manifest_entries () { # load mysql commands mysql_commands - + export LC_ALL=C PROGNAME=`basename $0` - PATH=${PATH}:/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin + PATH=${PATH}:/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin version=3.0 fields=5 # manifest fields From 41405ec29e4de47c936207d21d8144bc106a2541 Mon Sep 17 00:00:00 2001 From: John Grigutis Date: Thu, 23 Nov 2017 21:20:04 -0500 Subject: [PATCH 2/5] md5sum --> openssl md5 To support macOS which doesn't have md5sum. --- automysqlbackup | 4 ++-- install.sh | 26 +++----------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/automysqlbackup b/automysqlbackup index 4d2ff37..ecedec6 100755 --- a/automysqlbackup +++ b/automysqlbackup @@ -1153,7 +1153,7 @@ toggle_manifest() { check_manifest_entry() { local entry_md5sum [[ ! -e "${manifest_entry_to_check[0]}" ]] && { rm_manifest_entry_by_filename "${manifest_entry_to_check[0]}" 1 && return 1 || return 2; } - entry_md5sum="$(md5sum "${manifest_entry_to_check[0]}" | awk '{print $1}')" + entry_md5sum="$(openssl md5 "${manifest_entry_to_check[0]}" | awk '{print $2}')" if [[ "${entry_md5sum}" != "${manifest_entry_to_check[1]}" ]]; then printf 'g/%s/s//%s/g\nw\nq' "${manifest_entry_to_check[1]}" "${entry_md5sum}" | ed -s "$1" else @@ -1432,7 +1432,7 @@ add_manifest_entry() { id="${filename%.@(diff|sql)*}" id="${id:(-8):8}" #id="$(echo $filename | sed -re 's/.*_[0-9]{2}h[0-9]{2}m_([^\.]*)\..*/\1/')" - md5sum="$(md5sum "$filename" | awk '{print $1}')" + md5sum="$(openssl md5 "$filename" | awk '{print $2}')" if [[ "x$parent_id" = 'x' ]]; then echo -e "${filename}\tmd5sum\t${md5sum}\tdiff_id\t${id}\trel_id\t0\tdb\t${db}" >> "$1" else diff --git a/install.sh b/install.sh index 3209e8a..01263b2 100755 --- a/install.sh +++ b/install.sh @@ -425,29 +425,9 @@ while [ $i -lt $n ]; do printf "failed\n" exit 1 fi - if [[ "$OSTYPE" == "linux-gnu" ]]; then - # Linux - MD5_CHECK="md5sum --check" - elif [[ "$OSTYPE" == "darwin"* ]]; then - # Mac OSX - MD5_CHECK="md5 -r" - elif [[ "$OSTYPE" == "cygwin" ]]; then - # POSIX compatibility layer and Linux environment emulation for Windows - MD5_CHECK="md5sum --check" - elif [[ "$OSTYPE" == "msys" ]]; then - # Lightweight shell and GNU utilities compiled for Windows (part of MinGW) - MD5_CHECK="md5sum --check" - elif [[ "$OSTYPE" == "win32" ]]; then - # I'm not sure this can happen. - MD5_CHECK="md5sum --check" - elif [[ "$OSTYPE" == "freebsd"* ]]; then - # FreeBSD - MD5_CHECK="md5sum --check" - else - echo "Unable to recognize system. I don't know which md5 check I should use." - exit 1 - fi - if echo "${precheck_files[$((2*$i+1))]} ${precheck_files[$((2*$i))]}" | $MD5_CHECK >/dev/null 2>&1; then + md5_sum=$(openssl md5 "${precheck_files[$((2*$i))]}") + md5_sum=${md5_sum##*= } + if [[ "${precheck_files[$((2*$i+1))]}" = "${md5_sum}" ]]; then printf "md5sum okay :)\n" else printf "md5sum failed :(\n" From e1eec013e5d27c4177b36a057c1442608cbe44f1 Mon Sep 17 00:00:00 2001 From: John Grigutis Date: Thu, 23 Nov 2017 21:20:26 -0500 Subject: [PATCH 3/5] Update checksum --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 01263b2..d001c45 100755 --- a/install.sh +++ b/install.sh @@ -409,7 +409,7 @@ parse_config_file () { echo "### Checking archive files for existence, readability and integrity." echo -precheck_files=( automysqlbackup 31e3b0fe937af7ba3c4015543cd2a848 +precheck_files=( automysqlbackup 8d6f85929aa9c3525a12d5c3e4491b75 automysqlbackup.conf b70bc8a814400cf41b8e6228d7bbc963 README b17740fcd3a5f8579b907a42249a83cd LICENSE 39bba7d2cf0ba1036f2a6e2be52fe3f0 From fbbca5396ed0e7122f8a4d17df9cd9b6a2ba5ac7 Mon Sep 17 00:00:00 2001 From: John Grigutis Date: Fri, 24 Nov 2017 19:23:45 -0500 Subject: [PATCH 4/5] sed -r --> sed -E -r isn't available in macOS sed, -E is --- automysqlbackup | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automysqlbackup b/automysqlbackup index ecedec6..ff7a7ed 100755 --- a/automysqlbackup +++ b/automysqlbackup @@ -101,7 +101,7 @@ load_default_config() { mysql_commands() { VERSION=`mysql -V | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` - NODOT_VER=`echo $VERSION | sed -r 's/\.//g'` + NODOT_VER=`echo $VERSION | sed -E 's/\.//g'` if [ "${CONFIG_mysql_dump_encrypted_login}" = "yes" ]; then export MYSQLDUMP="mysqldump --login-path=$CONFIG_mysql_dump_login_path" export MYSQLSHOW="mysqlshow --login-path=$CONFIG_mysql_dump_login_path" @@ -263,7 +263,7 @@ gzip_compression() { # @return: (none) # @deps: (none) remove_datetimeinfo () { - mv "$1" "$(echo "$1" | sed -re 's/_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}h[0-9]{2}m_(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|January|February|March|April|May|June|July|August|September|October|November|December|[0-9]{1,2})//g')" + mv "$1" "$(echo "$1" | sed -Ee 's/_[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}h[0-9]{2}m_(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|January|February|March|April|May|June|July|August|September|October|November|December|[0-9]{1,2})//g')" } export -f remove_datetimeinfo @@ -1431,7 +1431,7 @@ add_manifest_entry() { lock_manifest "$1" || return 1 id="${filename%.@(diff|sql)*}" id="${id:(-8):8}" - #id="$(echo $filename | sed -re 's/.*_[0-9]{2}h[0-9]{2}m_([^\.]*)\..*/\1/')" + #id="$(echo $filename | sed -Ee 's/.*_[0-9]{2}h[0-9]{2}m_([^\.]*)\..*/\1/')" md5sum="$(openssl md5 "$filename" | awk '{print $2}')" if [[ "x$parent_id" = 'x' ]]; then echo -e "${filename}\tmd5sum\t${md5sum}\tdiff_id\t${id}\trel_id\t0\tdb\t${db}" >> "$1" From 011b31bc47730acaf40dc8c0d1939b64025c66e8 Mon Sep 17 00:00:00 2001 From: John Grigutis Date: Fri, 24 Nov 2017 19:24:24 -0500 Subject: [PATCH 5/5] Removes du --si Not available in macOS --- automysqlbackup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automysqlbackup b/automysqlbackup index ff7a7ed..2c782ae 100755 --- a/automysqlbackup +++ b/automysqlbackup @@ -1990,7 +1990,7 @@ method_backup () { # -> finished information echo "Total disk space used for backup storage..." echo "Size - Location" - echo `du -hs --si "${CONFIG_backup_dir}"` + echo `du -hs "${CONFIG_backup_dir}"` echo echo "======================================================================" # <- finished information