Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 27 Next »

Product Version: 9.0
Last Modified: 06 Sep 2019

Background

In the Application-aware mode, NAKIVO Backup & Replication triggers custom scripts you provide, prior to making snapshots of LVM volumes.

If you run a VM with Linux or FreeBSD guest OS under Hyper-V, refer Hyper-V support article about supported Linux and FreeBSD versions.

Solution

To make application-aware mode working on Linux guest OS, you need to put custom scripts called pre-freeze-script and post-thaw-script into /usr/sbin directory and give them executive permissions. When the backup job starts running, NAKIVO Backup & Replication triggers these scripts prior to making snapshots of LVM volumes.

pre-freeze-script and post-thaw-script scripts require root permissions to be executed.

When a non-root user is used, scripts invocation will be done via sudo, therefore the following requirements must be met.

1. Provided credentials must have full access without a password in /etc/sudoers 

#User privilege specification
root ALL=(ALL:ALL) ALL
#Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
#Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
#See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
nakivo ALL=(ALL) NOPASSWD:ALL

2. If NAKIVO Backup & Replication logs into Amazon EC2 instance and there's no password for Linux user, provided credentials must have a password to execute sudo:

    1. Log into the instance via SSH client using pem key
    2. Execute sudo passwd ubuntu
    3. Open /etc/sudoers in a text editor
    4. Add ubuntu ALL=(ALL) NOPASSWD:ALL to the bottom of the file
    5. Open /etc/ssh/sshd_config in a text editor
    6. Add set up PasswordAuthentication yes
    7. Reboot the instance
    8. Log into the instance via SSH client without pem key, enter password

Scripts Examples

You can use VMware tools to perform specific operations before or after a backup. For example, if a virtual machine hosts an Oracle database and you want to quiesce the database before performing a backup, you can run a script using VMware tools. On Linux virtual machines, the script /usr/sbin/pre-freeze-script is executed when the software snapshot is created and /usr/sbin/post-thaw-script is executed when the software snapshot is finalized.

The following scripts are available to perform pre- or post-processing using VMware tools:

Operation

Procedure

Scripts

DB2

Scripts can be used to take a snapshot of a VM with the DB2 application. These scripts enable VMware to suspend I/O updates to the DB2 database until the VMware Linux guest snapshot is completed.


  1. On a Linux virtual machine, copy the pre-freeze-script and post-thaw-script to the /usr/sbin directory.
  2. Copy the write_suspend and write_resume scripts to a location where the DB2 database can execute them (preferably to a directory under DB2 home).
 pre-freeze-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su - db2inst2 -c /db2home/db2inst2/write_suspend
fi

 post-thaw-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su - db2inst2 -c /db2home/db2inst2/write_resume
fi

 write_resume.sh

#!/bin/sh

export INSTHOME=/db2home/db2inst2

date >> $INSTHOME/write_resume.log
echo "----START RESUME----" >> $INSTHOME/write_resume.log << EOF
EOF

$INSTHOME/sqllib/bin/db2 connect to test >> $INSTHOME/write_resume.log
echo "+++" >> $INSTHOME/write_resume.log << EOF_1
EOF_1

$INSTHOME/sqllib/bin/db2 set write resume for database >> $INSTHOME/write_resume.log
echo "+++" >> $INSTHOME/write_resume.log << EOF_2
EOF_2

echo "----END----" >> $INSTHOME/write_resume.log << EOF_3
EOF_3

 write_suspend.sh

#!/bin/sh

export INSTHOME=/db2home/db2inst2

date >> $INSTHOME/write_suspend.log
echo "----START SUSPEND----" >> $INSTHOME/write_suspend.log << EOF
EOF

#connect to the database
$INSTHOME/sqllib/bin/db2 connect to test >> $INSTHOME/write_suspend.log
echo "+++" >> $INSTHOME/write_suspend.log << EOF_1
EOF_1

#set write condition for database
$INSTHOME/sqllib/bin/db2 set write suspend for database >> $INSTHOME/write_suspend.log
echo "+++" >> $INSTHOME/write_suspend.log << EOF_2
EOF_2

echo "----END----" >> $INSTHOME/write_suspend.log << EOF_3
EOF_3

MAXDB

Scripts can be used to take a snapshot of a VM with the MAXDB application. These scripts enable VMware to suspend I/O updates to the MAXDB database until the VMware Linux guest snapshot is completed.


  1. On a Linux virtual machine, copy the pre-freeze-script and post-thaw-script to the /usr/sbin directory.
  2. Copy suspend_logwriter and resume_logwriter scripts to a location where MAXDB database can execute them (preferably to a directory under MAXDB home).
 pre-freeze-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su - sdb -c /home/sdb/suspend_logwriter
fi

 post-thaw-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su - sdb -c /home/sdb/resume_logwriter
fi

 resume_logwriter.sh

#!/bin/sh

export INSTHOME=/home/sdb

date >> $INSTHOME/resume_logwriter.log
echo "----START RESUME----" >> $INSTHOME/resume_logwriter.log << EOF
EOF

#set resume logwriter for database
dbmcli -d MaxDB -u DBADMIN,DBADMIN util_execute resume logwriter >> $INSTHOME/resume_logwriter.log
echo "resume done" >> $INSTHOME/resume_logwriter.log << EOF_1
EOF_1


dbmcli -d MaxDB -u DBADMIN,DBADMIN util_release >> $INSTHOME/resume_logwriter.log
echo "release done" >> $INSTHOME/resume_logwriter.log << EOF_2
EOF_2

echo "----END----" >> $INSTHOME/resume_logwriter.log << EOF_3
EOF_3

 suspend_logwriter.sh

#!/bin/sh

export INSTHOME=/home/sdb

date >> $INSTHOME/suspend_logwriter.log
echo "----START SUSPEND----" >> $INSTHOME/suspend_logwriter.log << EOF
EOF

#connect to the database
dbmcli -d MaxDB -u DBADMIN,DBADMIN util_connect DBADMIN,DBADMIN >> $INSTHOME/suspend_logwriter.log
echo "util_connect done" >> $INSTHOME/suspend_logwriter.log << EOF_1
EOF_1

#set suspend logwriter for database
dbmcli -d MaxDB -u DBADMIN,DBADMIN util_execute suspend logwriter >> $INSTHOME/suspend_logwriter.log
echo "suspend logwriter done" >> $INSTHOME/suspend_logwriter.log << EOF_2
EOF_2

echo "----END----" >> $INSTHOME/suspend_logwriter.log << EOF_3
EOF_3

Oracle

Scripts can be used to take a snapshot of a VM with the Oracle application. These scripts enable VMware to suspend I/O updates to the Oracle database until the VMware Linux guest snapshot is completed.


  1. On a Linux virtual machine, copy the pre-freeze-script and post-thaw-script to the /usr/sbin directory.
  2. Copy the pre-freeze-script.sql and post-thaw-script.sql scripts to a location where the Oracle database can execute them (preferably to a directory under Oracle home).

These scripts change the entire database to backup mode.

If the virtual machine has the Oracle iDataAgent installed on it, you can also use the consistent-archivelog-backup.rman script as a sample to run archivelog backup. This script gets a consistent snapshot, all the latest archived logs, and the current control file.

 pre-freeze-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su oracle -c /oracle/oracle11g/DBA_SCRIPTS/pre-freeze.sql
fi

 post-thaw-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su oracle -c /oracle/oracle11g/DBA_SCRIPTS/post-thaw.sql

fi

###################################
##IF USER WANTS TO RUN A ARCHIVELOG AND CONTROLFILE BACKUP AFTER TAKING THE SNAP OF VM. HE CAN INSTALL ORACLE IDA ON THE GUEST VM AND USE BELOW SCRIPT AS SAMPLE AND MODIFY AND RUN AN ARCHIVE LOG AND CURRENT CONTROL FILE BACKUP. THIS MAKE THE VM CRASH CONSISTENT TO THIS POINT IN TIME.
#########################################

##if [ "$(id -u)" -eq "0" ]; then
##exec su oracle -c /oracle/oracle11g/DBA_SCRIPTS/consistent-archivelog-backup.rman
##fi

 pre-freeze-script.sql

export ORACLE_HOME=/oracle/oracle11g
$ORACLE_HOME/bin/sqlplus "sys/sys@KPNDB as sysdba" <<EOF
spool $ORACLE_HOME/DBA_SCRIPTS/pre-freeze.log;
alter database begin backup;
spool off;
EOF

 post-thaw-script.sql

export ORACLE_HOME=/oracle/oracle11g
/oracle/oracle11g/bin/sqlplus "sys/sys@KPNDB as sysdba" <<EOF
spool /oracle/oracle11g/DBA_SCRIPTS/post-thaw.log;
alter database end backup;
spool off;
EOF

 consistent-archivelog-backup.rman

export ORACLE_HOME=/oracle/oracle11g
$ORACLE_HOME/bin/rman target sys/sys@VMFSDB catalog vmfsdb/shankar@CATDB <<EOF1
spool log to $ORACLE_HOME/DBA_SCRIPTS/archivelog-backup.log
run
{
allocate channel ch1 type 'sbt_tape'
PARMS="SBT_LIBRARY=/opt/commvault/Base/libobk.so,ENV=(CvOraSID=VMFSDB,CvClientName=VMOracleVMFS,CvInstanceName=Instance001),BLKSIZE=262144";
sql 'alter system archive log current';
backup filesperset 32
(archivelog all);
backup current controlfile ;
}
spool off
EOF1


Sybase

Scripts can be used to take a snapshot of a VM with the Sybase application. These scripts enable VMware to suspend I/O updates to the Sybase database until the VMware Linux guest snapshot is completed.


  1. On a Linux virtual machine, copy the pre-freeze-script and post-thaw-script to the /usr/sbin directory.
  2. Copy pre-freeze-script.sql and post-thaw-script.sql scripts to a location where the Sybase database can execute them (preferably to a directory under Sybase home).

    These scripts execute Sybase quiesce commands that stop updates to the databases.

 pre-freeze-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su sybase -c /sybase/sybase15.7/scripts/pre-freeze-script.sql
fi

 post-thaw-script

#!/bin/sh

if [ "$(id -u)" -eq "0" ]; then
exec su sybase -c /sybase/sybase15.7/scripts/post-thaw-script.sql
fi

 pre-freeze-script.sql

if [ -f /sybase/sybase15.7/scripts/pre-freeze-script.out ]
then
rm -rf /sybase/sybase15.7/scripts/pre-freeze-script.out
fi

export SYBASE=/sybase/sybase15.7
export SYBASE_SERVER=DBSERVE99

$SYBASE/OCS-15_0/bin/isql -SKPNSYBASE -Usa -P -e -n -o /sybase/sybase15.7/scripts/pre-freeze-script.out << EOF
select getdate()
go
quiesce database tag1 hold pubs2,pubs3,sybsystemdb,sybsystemprocs,model
go
select is_quiesced(4)
go
select is_quiesced(5)
go
quiesce database tag2 hold master
go
EOF

 post-thaw-script.sql

if [ -f /sybase/sybase15.7/scripts/post-thaw-script.out ]
then
rm -rf /sybase/sybase15.7/scripts/post-thaw-script.out
fi

export SYBASE=/sybase/sybase15.7
export SYBASE_SERVER=DBSERVE99
$SYBASE/OCS-15_0/bin/isql -SKPNSYBASE -Usa -P -e -n -o /sybase/sybase15.7/scripts/post-thaw-script.out<< EOF
select getdate()
go
quiesce database tag2 release
go
quiesce database tag1 release
go
select is_quiesced(4)
go
select is_quiesced(5)
go
EOF

MySQL

Scripts can be used to take a snapshot of a VM with the MySQL application. These scripts enable VMware to suspend I/O updates to the MySQL database until the VMware Linux guest snapshot is completed.


  1. On a Linux virtual machine, copy the pre-freeze-script and post-thaw-script to the /usr/sbin directory.
  2. Copy the quiesce.py and unquiesce.py scripts to a location where the MySQL database can execute them (preferably to the /usr/sbin directory).

A Python script is used to quiesce and unquiesce the databases. Python and MySQL-Python modules must be installed on the client computer.

 pre-freeze-script

#!/bin/sh

#pre-freeze-script

date >> '/scripts/pre_root.log'
echo -e "\n attempting to run pre-freeze script for MySQL as root user\n" >> /scripts/pre_root.log
if [ "$(id -u)" -eq "0" ]; then
python '/scripts/quiesce.py' &
echo -e "\n executing query flush tables with read lock to quiesce the database\n" >> /scripts/pre-freeze.log
echo -e "\n Database is in quiesce mode now\n" >> /scripts/pre-freeze.log
else
date >> '/scripts/pre_root.log'
echo -e "not root useri\n" >> '/scripts/pre_root.log'
fi

 post-thaw-script

#!/bin/sh

#post-thaw-script

date >> '/scripts/post_root.log'
echo -e "\n attempting to run post-thaw script for MySQL as root user\n" >> /scripts/post_root.log
if [ "$(id -u)" -eq "0" ]; then
python '/scripts/unquiesce.py'
else
date >> '/scripts/post_root.log'
echo -e "not root useri\n" >> '/scripts/post_root.log'
fi

 unquiesce.py

import MySQLdb
import os
import time
import datetime
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
file1 = open("/scripts/post-thaw.log","a+" )
try:
os.remove('/tmp/freeze_snap.lock')
time.sleep(2)
except Exception, e:
print e
try:
conn = MySQLdb.connect ('localhost' , 'root' , 'password' )
cur = conn.cursor()
cur.execute ("select version()")
data = cur.fetchone()
file1.write (dt)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
file1.write ("\t MySQL version is %s: "%data)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
except:
file1.write (dt)
file1.write("\t unable to connect to MySQL server\n")

try:
file1.write (dt)
file1.write ("\t executing query to unquiesce the database \n")
cur.execute ("unlock tables")
file1.write (dt)
file1.write ("\t Database is in unquiesce mode now \n")
except:
file1.write(dt)
file1.write( "\n unexpected error from MySQL, unable to unlock tables. Please check MySql error logs for more info \n")

cur.close()
conn.close()

 quiesce.py

import MySQLdb
import os
import time
import datetime
dt=datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
file1 = open("/scripts/pre-freeze.log","a+" )
try:
conn = MySQLdb.connect ('localhost' , 'root' , 'password' )
cur = conn.cursor()
cur.execute ("select version()")
data = cur.fetchone()
file1.write (dt)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")
file1.write ("\t MySQL version is %s: "%data)
file1.write ("-------------------------------------------\n")
file1.write ("-------------------------------------------\n")

except:
file1.write (dt)
file1.write("\t unable to connect to MySQL server\n")

file2 = open ('/tmp/freeze_snap.lock', 'w')
file2.close()

try:
cur.execute (" flush tables with read lock ")
file1.write (dt)
file1.write ("\t using quiesce.py script - quiesce of database successful \n")
except:
file1.write(dt)
file1.write( "\n unexpected error from MySQL, unable to do flush tables with read lock, Please check MySQL error logs for more info\n")
while True:
check = os.path.exists ("/tmp/freeze_snap.lock")
if check == True:
continue
else:
break

  • No labels