Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I take a bcp dump from sybase using perl? 1

Status
Not open for further replies.

Sina

Technical User
Jan 2, 2001
309
CA
Hello everyone,

I'm looking for a script to take a bcp dump of a database from sybase and load it to another sybase database.

So basically connect to source server, take a dump of sourcedb and load that dump on to the destination server.

I really wold like to do that with perl using perl module.

Can anyone help with a sample script?

Thank you.
 
hello,

i wrote this perl script to bcp out a table from a source database and bcp in to a target database table... this perl script does not require a sybase module... this also assumes that you are using ASE 12.0... if not, just change the bin path in the script... try something like this just change the bcp out line to dump and bcp in line to load...

#! /usr/bin/perl
#
## USE THE MODULES NEEDED FOR THIS PROGRAM.
#
use FileHandle;

#
## ARGUMENTS
#
while ($#ARGV >= 0)
{
($_, $val) = getArgument($ARGV[0]);

SWITCH:
{
if (/^sourceDatabase$/) { $db1 = $val; last SWITCH }
if (/^sourceTable$/) { $table1 = $val; last SWITCH }
if (/^sourceUser$/) { $user1 = $val; last SWITCH }
if (/^sourcePassword$/) { $password1 = $val; last SWITCH }
if (/^sourceServer$/) { $server1 = $val; last SWITCH }
if (/^targetDatabase$/) { $db2 = $val; last SWITCH }
if (/^targetTable$/) { $table2 = $val; last SWITCH }
if (/^targetUser$/) { $user2 = $val; last SWITCH }
if (/^targetPassword$/) { $password2 = $val; last SWITCH }
if (/^targetServer$/) { $server2 = $val; last SWITCH }
if (/^out$/) { $outPath = $val; last SWITCH }
}

shift ARGV;
}

#
## RUN BCP OUT.
#
system (`/usr/sybase/OCS-12_0/bin/bcp $database1..$table1 out $outPath/$table.dat -U$user1 -P$password1 -S$server1 -c -t "|" -r "\n"`);

#
## TRUNCATE THE TABLE.
#
system (`/usr/sybase/OCS-12_0/bin/isql -U$user2 -P$password2 -S$server2 -o$outPath/truncate$table2.out`);

#
## RUN BCP IN.
#
system (`/usr/sybase/OCS-12_0/bin//bcp $database2..$table2 in $outPath/$table2.dat -U$user2 -P$password2 -S$server2 -b20000 -c -t "|" -r "\n"`);

#
## SUBROUTINE.
#
sub getArgument
{
return split(/=/, $_[0]);
}
-----------

here's the usage:

MyScriptName.pl sourceDatabase=MySourceDatabaseName sourceTable=MySourceTableName sourceUser=sa sourcePassword=MySourcePassword sourceServer=MySourceServerName targetDatabase=MyTargetDatabaseName targetTable=MyTargetTableName targetUser=sa targetPassword=MyTargetPassword targetServer=MyTargetServerName out=MyOutputPath <ENTER>

let me know if it works...

hth,
q.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top