Discussions specific to the VMware vSphere hypervisor
Post Reply
bslit
Novice
Posts: 3
Liked: never
Joined: Feb 06, 2015 9:10 am
Contact:

Linux MySQL/MariaDB Backup Script

Post by bslit » May 16, 2018 9:38 am

Case ID# 03002513

We are having troubles with the MySQL/MariaDB Script.
We followed the instructions on the Veeam White Paper form: https://www.veeam.com/wp-consistent-pro ... riadb.html
We are using the Hot backup – Database freezing method with the following Scripts.
Please note, we slightly modified the script with the –h option at the mysql command as we are connecting with SSL and need to connect with the hostname instead of localhost. The connection works fine, this isn’t a problem.
Pre-freeze script:

Code: Select all

#!/bin/bash -xv
# config:
# when running on debian we can use existing debian-sys-maint account using defaults file
# otherwise, specify username and password below using use_credentials
#use_credentials="-u root -p"
#defaults_file="/etc/my.cnf"
defaults_file="/etc/my.cnf.d/veeambackup-client.cnf"
timeout=300
lock_file=/tmp/mysql_tables_read_lock
###
if [ -f $defaults_file ]; then
opts="--defaults-file=$defaults_file"
fi
if [ -n $use_credentials ]; then
opts="$opts $use_credentials"
fi
sleep_time=$((timeout+10))
rm -f $lock_file
echo "$0 executing FLUSH TABLES WITH READ LOCK" | logger
mysql $opts -h "HOSTNAME.DOMAIN.EXAMPLE" --execute="FLUSH TABLES WITH READ LOCK; system touch $lock_file; system nohup sleep $sleep_time; system echo\ lock released|logger;" > /dev/null & mysql_pid=$!
echo "$0 child pid $mysql_pid" | logger
c=0
while [ ! -f $lock_file ]
do
# check if mysql is running
if ! ps -p $mysql_pid 1>/dev/null; then
echo "$0 mysql command has failed (bad credentials?)" | logger
exit 1
fi
sleep 1
c=$((c+1))
if [ $c -gt $timeout ]; then
echo "$0 timed out waiting for lock" | logger
touch $lock_file
kill $mysql_pid
fi
done
echo $mysql_pid > $lock_file
exit 0
Post-thaw script:

Code: Select all

#!/bin/bash -xv
lock_file=/tmp/mysql_tables_read_lock
###
mysql_pid=$(cat $lock_file)
echo "$0 sending sigterm to $mysql_pid" | logger
pkill -9 -P $mysql_pid
rm -f $lock_file
exit 0
When running the scripts manually, not through veeam, (first pre-freeze and then post-thaw afterwards) we get the following error message:

Code: Select all

#!/bin/bash -xv
lock_file=/tmp/mysql_tables_read_lock
+ lock_file=/tmp/mysql_tables_read_lock
###
mysql_pid=$(cat $lock_file)
++ cat /tmp/mysql_tables_read_lock
+ mysql_pid=14023
echo "$0 sending sigterm to $mysql_pid" | logger
+ echo './post-thaw_mysqldump-script.sh sending sigterm to 14023'
+ logger
pkill -9 -P $mysql_pid
+ pkill -9 -P 14023
ERROR at line 1: Unknown command '\ '.
rm -f $lock_file
+ rm -f /tmp/mysql_tables_read_lock
exit 0
+ exit 0
We know the error has it’s source in the pre-freeze script at the line:
mysql $opts -h " HOSTNAME.DOMAIN.EXAMPLE " --execute="FLUSH TABLES WITH READ LOCK; system touch $lock_file; system nohup sleep $sleep_time; system echo\ lock released|logger;" > /dev/null & mysql_pid=$!
If we were to omit the backslash after echo and just leave the line as followed, we wouldn’t get an error:
mysql $opts -h " HOSTNAME.DOMAIN.EXAMPLE " --execute="FLUSH TABLES WITH READ LOCK; system touch $lock_file; system nohup sleep $sleep_time; system echo lock released|logger;" > /dev/null & mysql_pid=$!
Question:
Is there a typo in the white paper and shouldn’t there be a backslash after the echo command? So the command would look like:
… system echo lock released|logger; …
What’s the purpose of the command if the backslash is needed?
… system echo\ lock released|logger; …
How can we fix the issue if the backslash is needed?

System:
CentOS Linux release 7.4.1708 (core) (Compatibility: ESXi 6.5 and higher (VM-Version 13))
MariaDB 5.5.56
Hypervisor: VMware ESXi 6.5.0 Build 7119157

PTide
Veeam Software
Posts: 4320
Liked: 355 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by PTide » May 16, 2018 12:03 pm 1 person likes this post

Hi,

To the best of my knowledge there should be no backslash so it's probably a typo. Have you tried to omit it? It won't do harm - the piece of code is just just calling bash command "echo" to pipe "lock released" message to logger so it writes it to the system log.

Thanks

bslit
Novice
Posts: 3
Liked: never
Joined: Feb 06, 2015 9:10 am
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by bslit » May 17, 2018 6:49 am

PTide wrote:Hi,

To the best of my knowledge there should be no backslash so it's probably a typo. Have you tried to omit it? It won't do harm - the piece of code is just just calling bash command "echo" to pipe "lock released" message to logger so it writes it to the system log.

Thanks

Hello,

Firstly thank you for the quick reply.

Yes we tried to omit it already before posting here. The scripts ran without errors when omitting the backslash, so this raised the question if the backslash just was a typo in the white paper or if really the command "echo\" was meant, which as you know has a different usage. So thank you for clearing things, we will omit the backslash in the script.


Cheers

pdimarco
Veeam Software
Posts: 220
Liked: 18 times
Joined: Sep 02, 2014 7:25 am
Full Name: Pascal DiMarco
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by pdimarco » May 17, 2018 12:44 pm 1 person likes this post

Hi,

Please ignore this backslash if you copy/past the script. It is a common way to tell you that the carriage return should be ignored in the document you are reading.

You can dowlnload the scripts on our github: https://github.com/VeeamHub/application ... ster/mysql

Cheers
Pascal

bslit
Novice
Posts: 3
Liked: never
Joined: Feb 06, 2015 9:10 am
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by bslit » May 22, 2018 6:36 am

pdimarco wrote:Hi,

Please ignore this backslash if you copy/past the script. It is a common way to tell you that the carriage return should be ignored in the document you are reading.

You can dowlnload the scripts on our github: https://github.com/VeeamHub/application ... ster/mysql

Cheers
Pascal
Hi,

Thanks for the explanation and the link, it will be handy in the future.

Cheers

whman
Novice
Posts: 5
Liked: never
Joined: Jun 12, 2018 4:54 pm
Contact:

[MERGED] Conflicting advice from white paper and KBs?

Post by whman » Jun 12, 2018 10:47 pm

From what I've read Application-Aware Processing isn't meant to be applied to Linux agents, instead they should use quiescence. I really do like the suggestion in the white paper though - it would mean that I don't have to create another backup job to use pre/post thaw scripts on just one of my machines (while the others don't use pre/post thaw scripts).

https://www.veeam.com/consistent-protec ... db_wpp.pdf

Or is it a matter of disabling all the windows related settings after enabling application-aware image processing? I'm a little confused - has anyone used application aware processing with linux successfully before?

v.Eremin
Veeam Software
Posts: 15142
Liked: 1141 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Conflicting advice from white paper and KBs?

Post by v.Eremin » Jun 13, 2018 11:03 am

Are you talking about VM backup job or Agent Backup policy? Thanks.

whman
Novice
Posts: 5
Liked: never
Joined: Jun 12, 2018 4:54 pm
Contact:

Re: Conflicting advice from white paper and KBs?

Post by whman » Jun 15, 2018 6:33 pm

I have VM Backup Jobs in mind. I haven't used the Agent before.

PTide
Veeam Software
Posts: 4320
Liked: 355 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Conflicting advice from white paper and KBs?

Post by PTide » Jun 16, 2018 3:26 pm

Hi,
Application-Aware Processing isn't meant to be applied to Linux agents
Not exactly. Pre-freeze/post-thaw scripts will work on Linux VMs too if you specify them under AAIP settings. That is, you can use either quiescence to trigger scripts residing on the VM, or pre-freeze/post-thaw scripts to make VBR push scripts to the guest. Please note that it is possible to assign different scripts do different VMs so you can have a mix of Windows and Linux VMs in the same job.

Thanks

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests