Host-based backup of VMware vSphere VMs.
Post Reply
bslit
Novice
Posts: 3
Liked: never
Joined: Feb 06, 2015 9:10 am
Contact:

Linux MySQL/MariaDB Backup Script

Post by bslit »

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
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by PTide » 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 »

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: 292
Liked: 38 times
Joined: Sep 02, 2014 7:25 am
Full Name: Pascal DiMarco
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by pdimarco » 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 »

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
Service Provider
Posts: 5
Liked: never
Joined: Jun 12, 2018 4:54 pm
Contact:

[MERGED] Conflicting advice from white paper and KBs?

Post by whman »

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?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Conflicting advice from white paper and KBs?

Post by veremin »

Are you talking about VM backup job or Agent Backup policy? Thanks.
whman
Service Provider
Posts: 5
Liked: never
Joined: Jun 12, 2018 4:54 pm
Contact:

Re: Conflicting advice from white paper and KBs?

Post by whman »

I have VM Backup Jobs in mind. I haven't used the Agent before.
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Conflicting advice from white paper and KBs?

Post by PTide »

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
jessie0
Enthusiast
Posts: 50
Liked: 5 times
Joined: Oct 16, 2019 5:04 am
Contact:

Re: Linux MySQL/MariaDB Backup Script

Post by jessie0 »

Hello pdimarco,

I have the same issue as the above. I have effected the corrections mentioned above(removing the \) but I still get the following error
"Error: Script finished execution with unexpected exit code: 1"
both

In my case, the only changes I made to the script was uncommenting the "use_credentials" line but I still get the error.
Please what am I doing wrong?

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests