Skip to content

Instantly share code, notes, and snippets.

@filipnet
Last active February 16, 2025 10:25
Show Gist options
  • Select an option

  • Save filipnet/527c51eccd5baa0140e888faffb2fc86 to your computer and use it in GitHub Desktop.

Select an option

Save filipnet/527c51eccd5baa0140e888faffb2fc86 to your computer and use it in GitHub Desktop.
This script updates the deprecated MySQL commands used in the automysqlbackup tool to their MariaDB equivalents. It replaces mysqldump with mariadb-dump, mysqlshow with mariadb-show, and mysql with mariadb, ensuring compatibility with newer MariaDB installations. A timestamped backup of the original file is created before applying the changes, p…
#!/bin/bash
# Script to update deprecated MySQL commands in the automysqlbackup file.
# The automysqlbackup project can be found at: https://sourceforge.net/projects/automysqlbackup/
#
# The following warnings have been observed when using automysqlbackup:
#
# mysqldump: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-dump' instead
# mysqlshow: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-show' instead
# mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead
#
# This script will replace these deprecated commands with their MariaDB equivalents
# and create a timestamped backup of the original file before making any changes.
# It is intended to help users transition to using MariaDB tools for backups.
# Path to the file that needs to be modified
FILE="/usr/local/bin/automysqlbackup"
# Check if the file exists
if [[ ! -f "$FILE" ]]; then
echo "Error: File $FILE not found!"
exit 1
fi
# Create a timestamped backup of the original file
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
BACKUP_FILE="$FILE.backup.$TIMESTAMP"
cp "$FILE" "$BACKUP_FILE"
# Replace deprecated commands with the new ones
sed -i 's/mysqldump/mariadb-dump/g' "$FILE"
sed -i 's/mysqlshow/mariadb-show/g' "$FILE"
# Replace only 'mysql' when it is followed by a space (to avoid replacing other instances)
sed -i 's/\bmysql\b/mariadb/g' "$FILE"
# Confirm the changes
echo "The file $FILE has been updated. A backup was created at $BACKUP_FILE."
@ulfkosack
Copy link

Thanks for this Script.

The mysql sed is to heavy for me. It replaces ../mysql/... too. On Debian you can overwrite some variables, so I had to replace it too.

Here my changes on a Debian 11:

--- fix_deprecated_mysql_tools_orig.sh  2025-02-16 11:19:42.678102234 +0100
+++ fix_deprecated_mysql_tools.sh       2025-02-16 11:11:39.527395376 +0100
@@ -14,7 +14,8 @@
 # It is intended to help users transition to using MariaDB tools for backups.

 # Path to the file that needs to be modified
-FILE="/usr/local/bin/automysqlbackup"
+FILE="/usr/sbin/automysqlbackup"
+#FILE="/etc/default/automysqlbackup"

 # Check if the file exists
 if [[ ! -f "$FILE" ]]; then
@@ -31,7 +32,7 @@
 sed -i 's/mysqldump/mariadb-dump/g' "$FILE"
 sed -i 's/mysqlshow/mariadb-show/g' "$FILE"
 # Replace only 'mysql' when it is followed by a space (to avoid replacing other instances)
-sed -i 's/\bmysql\b/mariadb/g' "$FILE"
+sed -i 's/\bmysql\b\s/mariadb /g' "$FILE"

 # Confirm the changes
 echo "The file $FILE has been updated. A backup was created at $BACKUP_FILE."

Thanks
Ulf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment