#! /usr/local/bin/sybperl 

#
#	@(#)dumpall.pl	1.1	5/25/93
#

# Change log
# date          author 	 purpose
# ??/??/??      D.Preuss creation/adaptation from sybperl example code
# 01/25/97	T.Boss	 accounted for new prod11 server.  Included logic to
# 			 populate sa pw for different servers
# 4/4/97	T.Boss	 comment out dump tran with trunate_only ... messing
#			 up Sql backtrack dump tran attempts the next day
#			 when sybperl dump database attempts fail...
# 4/11/97	T.Boss	 changed DUMPDIR to be /export/home1 b/c /news is
#			 just about full...excluded issc and hss from dump.

$ENV{'SYBASE'} = "/usr/sybase";
#$DUMPDIR = "/export/sybase";
$DUMPDIR = "/news";
require "/export/home/donp/sybase/spawn.pl";
require "sybperl.pl";
require "sql.pl";

#
# Log us in to Sybase.
#
#@servers = ("prod", "prod10");
@servers = ("prod");
#@servers = ("prod11", "prod");

foreach $server (@servers) {

$ENV{'DSQUERY'} = $server;
#$sapw = "xxxxxxxx"; # if ($server eq "prod");

if ($server eq "prod") {
     $sapw = "xxxxxxxx";
   }
   else {
     $sapw = "xxxxxxxx";
   } 

$d = &dblogin("sa", $sapw);

print "Dumping server $server\n";

$atfield = "at CC_BACKUP" if($server ne "prod");

&sql($d, "use master");
@dbs = &sql($d, "select name from sysdatabases order by name");

foreach $n (@dbs){
 next if ($n =~ /tempdb|pubs2|hss|CDB|issc/);
print "Will dump database $n from server $server\n";
#print "DBCC checking $n\n";
#    @output = &sql($d, dbcc checkdb($n)");
#	print @output;
$FILEDIR = "/news";
$DUMPFILE = "$DUMPDIR/$server/dump.$n";
$ZIPFILE = "$FILEDIR/$server/dump.$n.gz";

    unlink("$FILEDIR/dump.$n.gz");
#	&sql($d, "dump tran $n with truncate_only");
    &sql($d, "dump database $n to \"$DUMPFILE\" $atfield");
    &spawn("/usr/local/bin/gzip -c -1 $DUMPFILE > $ZIPFILE; rm $DUMPFILE");	
	sleep 5;
    chmod(0600,$ZIPFILE);

}
   &dbclose($d);
	sleep 60;
   &spawn("ls -lL $FILEDIR/$server | mail donp");
}