Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Product Version: 9.0
Last Modified: 06 September 2019

Problem

In the Applicationapplication-aware mode, NAKIVO Backup & Replication triggers provided custom scripts prior to making before taking snapshots of LVM volumes.

Note

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

Solution

To make For application-aware mode to work on Linux guest OS, you need to put the custom scripts called pre-freeze-script and post-thaw-script into /usr/sbin directory and give grant them executive permissions. When the backup job starts running, NAKIVO Backup & Replication triggers these scripts prior to making before snapshots of LVM volumes. The pre-freeze-script and post-thaw-script scripts require root permissions to be executed. When a non-root user is used, scripts script invocation will be is done via sudo, therefore the following requirements must be met.

...

2. If NAKIVO Backup & Replication logs into in to  an Amazon EC2 instance and there 's is no password for the 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 in to the instance via SSH client without pem key, enter password

Scripts Examples

VMware tools can be used to perform certain operations before or after a backup. For instance, if an Oracle database is hosted on a virtual machine and you need to freeze the database prior to backing it up, you can use VMware tools to run the correspondent script. On Linux VMs, the "/usr/sbin/pre-freeze-script" script  is executed when the software snapshot is created, and the "/usr/sbin/post-thaw-script" script is executed when the software snapshot is finalized.

The scripts in the table below can be used to perform freeze and thaw operations:

...

Operation Description

...

Operation

...

Scripts

...

DB2

On a virtual machine with the DB2 application, scripts can be used to suspend updates to the DB2 database until the snapshot is completed.

  1. 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).

l

Expand
titlepre-freeze-script

#!/bin/sh

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

Expand
titlepost-thaw-script

#!/bin/sh

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

...

titlewrite_resume.sh

...

Expand
titlewrite_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

On a virtual machine with the MAXDB application, scripts can be used to suspend updates to the MAXDB database until the snapshot is completed.

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

l

Expand
titlepre-freeze-script

#!/bin/sh

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

Expand
titlepost-thaw-script

#!/bin/sh

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

...

titleresume_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

...

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

Expand
titlesuspend_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

On a virtual machine with the Oracle application, scripts can be used to suspend updates to the Oracle database until the snapshot is completed.

  1. 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).

With these scripts, the backup mode will be applied to the entire database.

In case the VM has the Oracle iDataAgent installed, the consistent-archivelog-backup.rman script can be used as a model to run archivelog backup. It results in getting the consistent snapshot, all the latest archived logs, and the current control file.

l

Expand
titlepre-freeze-script

#!/bin/sh

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

Expand
titlepost-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

Expand
titlepre-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

Expand
titlepost-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

Expand
titleconsistent-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

On a virtual machine with the Sybase application, scripts can be used to suspend updates to the Sybase database until the snapshot is completed.

  1. 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.

l

Expand
titlepre-freeze-script

#!/bin/sh

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

Expand
titlepost-thaw-script

#!/bin/sh

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

Expand
titlepre-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

Expand
titlepost-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

On a virtual machine with the MySQL application, scripts can be used to suspend updates to the MySQL database until the snapshot is completed.

  1. 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.

l

Expand
titlepre-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

Expand
titlepost-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

Expand
titleunquiesce.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()

Expand
titlequiesce.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

SEO Metadata
composedTitleApplication-aware Mode for Linux VMs

In the Application-aware mode, NAKIVO Backup and Replication triggers custom scripts inside guest Linux OS of source VMs prior to making snapshots of LVM volumes.

...