0

我有一个简单的 Perl/DBI 程序来备份 SQL Server 数据库。该程序运行干净,没有产生错误,据说创建了数据库备份,但备份文件不存在!

当我通过 DBI 执行以下命令时,

backup database dz to disk='C:\SqlBackups\dz.perl' with init

不创建备份文件。Perl 和 SQL 报告“为数据库 'y' 处理了 x 页,
但是当我执行 DOS> dir 时没有出现备份文件

当我通过 SqlCmd 执行类似的命令时,

backup database dz to disk='C:\SqlBackups\dz.sqlcmd' with init

创建一个备份文件。

我正在运行 ActiveState Perl 版本这是为 Microsoft Windows 7 Professional Build 6.1(Build 7601;Service Pack 1)上的 MSWin32-x64-multi-thread 构建的 perl 5,版本 16,subversion 1 (v5.16.1)

这是程序

#!perl -w
#Test making database backups via Perl DBI 


#preparations
    use strict;  #require variable declaration 
    use DBI;      #database interface
    my $dbHandle = DBI->connect("dbi:ODBC:Driver={SQL Server};Server=DavidZokaites")  or die;
    $dbHandle->{TraceLevel} = "15|ALL";    #get maximum debugging information 


#loop over all databases that need a dump 
    foreach my $dbName (  qw < dz master model msdb my_test > ) 
    {
        #DBI method that runs but creates no dumps  
        my $query = "backup database $dbName to disk='C:\\SqlBackups\\$dbName.perl' with init";
        print $query, "\n"; 
        warn "\n$dbName\n";
        $dbHandle->do ($query)  or die; 

        #SQLCMD that works 
        $query = "backup database $dbName to disk='C:\\SqlBackups\\$dbName.sqlcmd' with init";
        print $query, "\n"; 
        my $sysCmd = "SqlCmd -S DavidZokaites -Q \"$query\" >> TestDbi.sqlcmd.out";
        system ($sysCmd) == 0
            or die "Unable to execute $sysCmd \n"; 
    } 

这里有一点 DBI stderr tracking

    DBI::db=HASH(0x297ba10) trace level set to 0x7f0fff00/15 (DBI @ 0x0/0) in DBI 1.622-ithread (pid 7712)

master
    !! info: '' CLEARED by call to do method
    -> do for DBD::ODBC::db (DBI::db=HASH(0x297bae8)~0x297ba10 'backup database master to disk='C:\SqlBackups\master.perl' with init') thr#1d97e8
    >> STORE         DISPATCH (DBI::db=HASH(0x297ba10) rc1/2 @3 g2 ima41c pid#7712) at C:/Perl64/site/lib/DBD/ODBC.pm line 424 via  at C:\David\DoBackup\TestDbi.pl line 20
1    -> STORE for DBD::ODBC::db (DBI::db=HASH(0x297ba10)~INNER 'Statement' 'backup database master to disk='C:\SqlBackups\master.perl' with init') thr#1d97e8
    !!DBD::ODBC unsupported attribute passed (Statement)
    STORE DBI::db=HASH(0x297ba10) 'Statement' => 'backup database master to disk='C:\SqlBackups\master.perl' with init'
1    <- STORE= ( 1 ) [1 items] at C:/Perl64/site/lib/DBD/ODBC.pm line 424 via  at C:\David\DoBackup\TestDbi.pl line 20
    SQLExecDirect backup database master to disk='C:\SqlBackups\master.perl' with init
    Processing non utf8 sql in unicode mode
    SQLExecDirect = 1
    !!dbd_error2(err_rc=1, what=Execute immediate success with info, handles=(26bd70,2699f00,29cd080)
    !SQLError(26bd70,2699f00,29cd080) = (01000, 4035, [Microsoft][ODBC SQL Server Driver][SQL Server]Processed 1376 pages for database 'master', file 'master' on file 1.)
    !! info: '' '[Microsoft][ODBC SQL Server Driver][SQL Server]Processed 1376 pages for database 'master', file 'master' on file 1. (SQL-01000)' (err#0)
    <- do= ( -1 ) [1 items] at C:\David\DoBackup\TestDbi.pl line 20
4

1 回答 1

0

您需要阅读为什么我在 MS SQL Server 中的备份/恢复/some_other_procedure 不完整?. 当您使用“do”方法未完成时,任何可以输出打印消息的命令/过程。使用准备/执行和 odbc_more_results。

于 2013-04-22T10:18:06.437 回答