File: backup_restore.pl

package info (click to toggle)
libdbd-odbc-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,272 kB
  • sloc: perl: 7,932; ansic: 5,991; makefile: 33; sql: 8
file content (27 lines) | stat: -rw-r--r-- 604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# $Id: backup_restore.pl 14631 2011-01-03 16:48:35Z mjevans $
# backup and restore a MS SQL Server database
# needs to loop over odbc_more_results or the procedure does not finish
use DBI;
use strict;
use warnings;
use Data::Dumper;

sub _error_handler {
    print Dumper(\@_);
    0;
}

my $h = DBI->connect;
$h->{RaiseError} = 1;
$h->{HandleError} = \&_error_handler;

eval {$h->do('create database foo');};

$h->do(q{backup database foo to disk='c:\foo.bak'});

my $s = $h->prepare(q{restore database foo from disk='c:\foo.bak'});
$s->execute;

while ($s->{odbc_more_results}) {
    print "More\n";
}