Auto Informix Backup Error
Posted in 2009
Topics: Backup & Restore, Logging & Checkpoints, Platform-Specific Issues
Trying to automate my informix backup.
This is my script so far:
______________________________________________________________________________
. ./ifasenv # this sets my environment variables
echo "Backing up Ifastest Logical Logs"
{
ontape -a << EOF
Y
EOF
} | tail -5 >> /backup_ifastest.log
echo "Backing up Ifastest Database"
ontape -s -L 0 << ^M |head -100 >> /backup_ifastest.log;
echo "Archive Complete"
----------------------------
The above script works, but after the ontape -s command runs, the script
completes and does not echo "Archive Complete".
Also saw other posts to change the ontape command to :
ontape -s << EOF
0
EOF |tail -5 >> /backup_ifastest.log
This flavor keeps erroring with "<<" unmatched.
Any suggestions why the "Archive Complete" message does not show?
Any suggestions for a better writen script?
Informix 9.4 on HP-UX 11.1
Thanks in advance.
Something we created and use. It may not be perfect, but it works for
multiple file backups.
$cat /usr/informix/Admin/cron_scripts/rrc_backup_exec.sh
#!/bin/ksh
. $1
rm /ifmx_backup/backup_*
/usr/informix/Admin/tools/bin/ibackupt.pl /ifmx_backup/backup_
cat
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
>> /usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup.log
echo >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
echo " sls0440 Backup File System with RRC " >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
echo >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
echo $(df -k | grep Filesystem) >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
echo $(df -k | grep ifmx_backup) >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
echo >>
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
SUFFIX=`hostname`.d`date "+%m%d%y"`
chmod 700
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
#rcp
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
cartman:/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_ma
il.log
rm
/usr/informix/Admin/Logs/backup_logs/${INFORMIXSERVER}_backup_mail.log
rsh lydia "rm /ifmx_backup/Backups_from_RRCs/*`hostname`*.tar.gz"
cp /ifmx_backup/backup_01.gz /ifmx_backup/backup_01_$SUFFIX.gz
chmod 700 /ifmx_backup/backup_01_$SUFFIX.gz
rcp /ifmx_backup/backup_01_$SUFFIX.gz
lydia:/ifmx_backup/Backups_from_RRCs/backup_01_$SUFFIX.gz
rm /ifmx_backup/backup_01_$SUFFIX.gz
cp /ifmx_backup/backup_02.gz /ifmx_backup/backup_02_$SUFFIX.gz
chmod 700 /ifmx_backup/backup_02_$SUFFIX.gz
rcp /ifmx_backup/backup_02_$SUFFIX.gz
lydia:/ifmx_backup/Backups_from_RRCs/backup_02_$SUFFIX.gz
rm /ifmx_backup/backup_02_$SUFFIX.gz
$cat /usr/informix/Admin/tools/bin/ibackupt.pl
#!/usr/bin/perl
use FileHandle;
use IPC::Open2;
#
# Set constants and arguments.
#
$ibdev = $ARGV[0] ;
# New files will have mode 660
umask 016;
sub prnt {
select LH;
$| = 1;
print LH @_ ;
}
#
# This function returns timestamp in the format "mm/dd/yy hh:mm:ss"
#
sub tstamp{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst ) =
localtime(time);
return sprintf("%02d/%02d/%04d %02d:%02d:%02d",
$mon+1,$mday,$year+1900,$hour,$min,$sec );
}
#
# This function returns today's date in the format "mmddyy"
#
sub today{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst ) =
localtime(time);
return sprintf("%02d%02d%04d", $mon+1,$mday,$year+1900 );
}
sub chk_device{
return if system( " [ -r @_ -a -w @_ ] " ) == 0 ;
if ( system( " [ -f @_ ] " ) == 0 ) {
prnt("File @_ has incorrect permissions.\\
");
exit( 1 );
}
return if ( system("touch @_") == 0 ) ;
prnt("Failed to create new file @_\\
");
exit(1);
}
sub cmp_device{
return if ( system("/usr/bin/gzip @_") == 0 ) ;
print("Failed to gzip compress file section @_\\
");
exit(1);
}
sub set_device{
( $ld, $rd, $num ) = @_;
unlink $ld || prnt("Unlink failed\\
") && die ;
$curdev = sprintf( "%s%02d", $rd, $num );
prnt("\\
Current backup device: ", $curdev, "\\
\\
" );
chk_device( $curdev );
symlink $curdev, $ld || prnt("Symbolic link failed.\\
") && die ;
}
sub set_device2{
( $ld, $rd, $num ) = @_;
cmp_device( $curdev );
unlink $ld || prnt("Unlink failed\\
") && die ;
$curdev = sprintf( "%s%02d", $rd, $num );
prnt("\\
Current backup device: ", $curdev, "\\
\\
" );
chk_device( $curdev );
symlink $curdev, $ld || prnt("Symbolic link failed.\\
") && die ;
}
sub get_backtape {
open( LTH, " onstat -c | grep '^TAPEDEV' | awk '{print \\\\$2}' |" ) ||
prnt( "onstat error\\
" ) && die ;
return( <LTH> );
}
sub sigtrap {
prnt("\\
Signal @_ received. Exiting. ", tstamp(), "\\
\\
" );
exit(1);
}
#
# Main program starts here.
#
die "Usage:$0 ifmx_backup_device" unless $ibdev;
$SIG{TERM} = 'sigtrap' ;
$SIG{QUIT} = 'sigtrap' ;
$SIG{INT} = 'sigtrap' ;
$SIG{STOP} = 'sigtrap' ;
#
# All output goes to log file and stdout.
# Open handler here.
#
$logfile="
/usr/informix/Admin/Logs/backup_logs/$ENV{\\\\"INFORMIXSERVER\\\\"}_backup_mai
l.log" ;
open( LH, ">> $logfile" ) || prnt( "Couldn't open logfile\\
" ) && die;
prnt("###################################################\\
");
prnt("Informix backup started: ", tstamp(), "\\
\\
");
prnt( "Server is ", $ENV{"INFORMIXSERVER"}, "\\
" );
chop ( $itd = get_backtape()) ;
$curnum = 1 ;
set_device( $itd, $ibdev, $curnum );
$pid = open2( \\\\*Reader, \\\\*Writer, "ontape -s -L 0");
Writer->autoflush();
$status = -1;
while( ! eof Reader ) {
read Reader, $char , 1;
$str .= $char ;
if( ($char eq "\\
") || (grep /\\\\.\\\\.\\\\./, $str) ||
grep /\\\\(y\\\\/n\\\\)/, $str ) {
if( (length $str) > 2 ) {
if( ++$lines > 250 ) {
prnt("\\
Too many output lines. Something is wrong. Stop here.",
tstamp(), "\\
\\
"
);
exit(1);
}
prnt( $str, "\\
") ;
@fields = split(" ", $str );
if( $fields[0] eq "Please" && $fields[1] eq "mount" &&
$fields[2] eq "tape" ) {
if ( $fields[3] > 1 ) {
set_device2( $itd, $ibdev, ++$curnum )
}
print Writer "\\
";
}
}
$status = 0 if( grep /Program over/, $str );
$str = $char = "";
}
}
$cstat = ( $status == 0 ) ? "completed: " : "failed: " ;
prnt("Informix backup ", $cstat, tstamp() ,"\\
\\
");
cmp_device( $curdev );
exit(0);
Thanks,
*******************************************************************
Ernie Knox
IT Database Administrator Specialist
Sears Holdings
3333 Beverly Rd., B4-266A
Hoffman Estates, IL. 60179
Office: (847) 286-5735
Email: Ernest.Knox@searshc.com
Blackberry: 2244650553@messaging.sprintpcs.com
Page via Skytel: 2244650553@sprint.skytel.com
Informix or MySQL Primary: 9110210@skytel.com
Informix or MySQL Secondary: 7276872@skytel.com
" Yes we can make a Change! "
" It's always a great day to watch Spo
Actually the second one should be:
ontape -s << EOF |tail -5 >> /backup_ifastest.log
0
EOF
For the first one, try getting rid of the call to head.
Art
Art S. Kagel
Oninit (www.oninit.com)
IIUG Board of Directors (art@iiug.org)
Disclaimer: Please keep in mind that my own opinions are my own opinions and
do not reflect on my employer, Oninit, the IIUG, nor any other organization
with which I am associated either explicitly or implicitly. Neither do
those opinions reflect those of other individuals affiliated with any entity
with which I am affiliated nor those of the entities themselves.
On Fri, Oct 2, 2009 at 5:14 PM, MONTE HEEREN <mheeren@aea11.k12.ia.us>wrote:
> Trying to automate my informix backup.
> This is my script so far:
>
>
______________________________________________________________________________
> .. ./ifasenv # this sets my environment variables
> echo "Backing up Ifastest Logical Logs"
> {
> ontape -a << EOF>
> Y
> EOF
> } | tail -5 >> /backup_ifastest.log
> echo "Backing up Ifastest Database"
> ontape -s -L 0 << ^M |head -100 >> /backup_ifastest.log;>
> echo "Archive Complete"
>
> ----------------------------
> The above script works, but after the ontape -s command runs, the script
> completes and does not echo "Archive Complete".
> Also saw other posts to change the ontape command to :
> ontape -s << EOF>
> 0
> EOF |tail -5 >> /backup_ifastest.log
>
>
> This flavor keeps erroring with "<<" unmatched.
>
> Any suggestions why the "Archive Complete" message does not show?
>
> Any suggestions for a better writen script?
>
> Informix 9.4 on HP-UX 11.1
>
> Thanks in advance.
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--0015174762a4f8578e047524c770
Related threads
- Fragmentation Fundamental Question
- LVARCHAR data type
- Re: SQL convert number into the date
- Re: Slow dbexport
- doubt about parameters (PDQ)