mohankrishna919
Programmer
I am new to perl
but after spending late nights for some days , i was able to generate code for database backup. the code will ask you enter servername , enter database name if i enter it will take backup
suppose my code is in backup.pl
now the thing is i need to get database backup by entering like this perl backup.pl -i servername -d databasename
if i hit enter it should take backup of given server name and database name.
My code:
use strict;
use Win32::SqlServer qw(SCALAR);
print "Please enter DB name:\n";
my $name = <STDIN>;
chomp($name);
# Log in to server .
my $sqlsrv = Win32::SqlServer::sql_init('localhost', 'geff', 'gentle', 'Northwind');
# Our SQL statement.
my $stmnt = <<SQLEND;
BACKUP database "$name" TO DISK = N'c:\\bak\\master.dmp'
SQLEND
# Run query.
my $result = $sqlsrv->sql($stmnt, SCALAR);
# Print results.
foreach my $name (@$result) {
print "$name\n";
}
but after spending late nights for some days , i was able to generate code for database backup. the code will ask you enter servername , enter database name if i enter it will take backup
suppose my code is in backup.pl
now the thing is i need to get database backup by entering like this perl backup.pl -i servername -d databasename
if i hit enter it should take backup of given server name and database name.
My code:
use strict;
use Win32::SqlServer qw(SCALAR);
print "Please enter DB name:\n";
my $name = <STDIN>;
chomp($name);
# Log in to server .
my $sqlsrv = Win32::SqlServer::sql_init('localhost', 'geff', 'gentle', 'Northwind');
# Our SQL statement.
my $stmnt = <<SQLEND;
BACKUP database "$name" TO DISK = N'c:\\bak\\master.dmp'
SQLEND
# Run query.
my $result = $sqlsrv->sql($stmnt, SCALAR);
# Print results.
foreach my $name (@$result) {
print "$name\n";
}