ADSM-L

Re: MS-Exchange agent -- backup deletion

1998-06-29 10:25:57
Subject: Re: MS-Exchange agent -- backup deletion
From: "Gogineni, Sri" <SGogineni AT CAISO DOT COM>
Date: Mon, 29 Jun 1998 07:25:57 -0700
Some good person(Phil Chissell) on the site had posted some material. I
am pasting it as is. Please do not forget to thank the person concerned
and not me. they are some perl scripts to delete exchange stores after
certain days. you might need to test out this.


WARNING: LONG APPEND FOLLOWS

Christo,

Here are the attachments that Phil Chissell sent.
I detached them and placed them in-line.
Special thanks to Phil for his willingness to share!

*********
SQL Agent
*********
=========================================================
=========================================================
File: SQL_backup.bat
--------------------
@echo off
@echo off
rem Batch file to backup SQL databases
rem Author: Phil Chissell
rem Date: 02/12/1997

set drive=D:
set adsm_dir=ADSM_V3
set adsm_sql=AGENTSQL
set adsm_cmds=NP_CMDS
set log_file=DSMSCHED.LOG
set backuplog=%drive%\%adsm_dir%\%adsm_sql%\%log_file%
set get_dbs=%drive%\%adsm_dir%\%adsm_cmds%\sql_get_dbs.pl
set old_dbs=%drive%\%adsm_dir%\%adsm_cmds%\sql_list_old_dbs.pl
set tempfile_in=tmp_sql_lst.in
set tempfile_out=tmp_sql_lst.out
set old_dbs_in=tmp_old_sql.in
set old_dbs_out=tmp_old_sql.out
set window=7

:SQLBackup
echo Starting the SQL database backups on %computername% now >>
%backuplog%

CD /d %drive%\%adsm_dir%\%adsm_sql%

rem Get the list of SQL databases

sqldsmc /sqlsecure /sqlquerydb > %tempfile_in%

rem Use the following perl script to munge the data into the appropriate
format

perl %get_dbs% %tempfile_in% %tempfile_out%

for /f %%i in (%tempfile_out%) do sqldsmc /sqlsecure /backupfull:%%i
/truncafter /logfile:%backuplog%

:ADSMCleanup
rem Clean up old databases

echo Removing old databases from the ADSM Server >> %backuplog%

rem Get the list of old (more than 7 days) SQL databases
rem on the ADSM Server via the perl script below

sqldsmc /adsmquerydb > %old_dbs_in%

perl %old_dbs% %window% %old_dbs_in% %old_dbs_out%

for /f %%i in (%old_dbs_out%) do sqldsmc /adsmdelete:%%i
/logfile:%backuplog%

:exit
echo Backup script has finished >> %backuplog%

exit
=========================================================
=========================================================
File: sql_get_dbs.pl
--------------------
#!perl.exe
#!perl.exe
#
# sql_get_dbs.pl
#
# This script munges  a list of SQL databases into the appropriate
format

open (OUT,">$ARGV[1]") || die "Could not create \$ARGV[1] \n";
open (IN, "$ARGV[0]");
while (<IN>) {
if (/^---*/) { $Flag=1; }
if ( $Flag == 1 && /^[a-zA-Z0-9]/ ) {
        ($db,$junk) = split(/\s/);
        print OUT "$db\n";
        }
}
close IN;
close OUT;
exit 0;
=========================================================
=========================================================
File: sql_list_old_dbs.pl
-------------------------
#!perl.exe
#!perl.exe
#
# sql_list_old_dbs.pl
#
# This script generates a list of databases which are greater than
# 6 days old and writes them to a temporary file

# allow window to be specified as a parameter

if ($ARGV[0]) { $w=$ARGV[0]; } else { $w=7; }

$start=0;

open (OUT,">$ARGV[2]") || die "ERROR: can't open \$ARGv[2] \n";
open (IN,"$ARGV[1]");

# evaluate 7 days ago date string

@days=(31,28,31,30,31,30,31,31,30,31,30,31);
(@now)=localtime(time);

# check numbers for 0 padding and millenium

if ( $now[5] =~ /^9[89]$/ ) { $now[5]=~s/^/19/; }
elsif ($now[5] =~ /^[0..9][0..7]$/) { $now[5]=~s/^/20/; }

# note above should be valid for 100 yrs or until the year is 4 digits

if (length($now[4]+=1)==1) { $now[4]=~s/^/0/; }
if (length($now[3])==1) { $now[3]=~s/^/0/; }

#decide if year is a leap year
# if a year is exactly divisible by 4 and NOT exactly divisible by 100
but is
divisible by 400

if (($now[5]%4==0 && $now[5]%100!=0)||($now[5]%100==0 &&
$now[5]%400==0))
    { $days[1]=29; }

# now derive 7 days ago marker

if ($now[4] == '01' && $now[3] < '07') {
 $ago7=($now[5]-1).'12'.sprintf("%02.2d",31-$w+$now[3]);
 }
elsif ($now[3] < '08') {

$ago7=$now[5].sprintf("%02d%02d",$now[4]-1,$days[$now[4]-2]-$w+$now[3]);
 }
else { $ago7=$now[5].$now[4].sprintf("%02d",$now[3]-$w); }

# process each line of adsm report and write old logs to OUT

while (<IN>) {
if (/^-----/) { $start = 1; next; }
if ($start && /^[a-zA-Z]/) {
 chop;
 (@fields)=split(/[ ]+/);
 ($m,$d,$y)=split('/',$fields[4]);
 $testnum=$y.$m.$d;
 if($testnum<$ago7) {
  $cut=join('',$fields[1],',',$fields[6],"\n");
  push(@array,$cut); }
 }
}
print OUT @array;
close OUT;
close IN;

exit 0;

# end of script
=========================================================

**************
Exchange Agent
**************
=========================================================
File: Exchange_backup.bat
-------------------------
@echo off
@echo off
rem Batch file to backup Exchange
rem Author: Phil Chissell
rem Date: 07/05/1998

set drive=D:
set adsm_dir=ADSM_V3
set adsm_exc=AGENTEXC
set adsm_cmds=NP_CMDS
set log_file=DSMSCHED.LOG
set backuplog=%drive%\%adsm_dir%\%adsm_exc%\%log_file%
set old_dbs=%drive%\%adsm_dir%\%adsm_cmds%\exc_list_old_dbs.pl
set old_dbs_in=tmp_old_exc.in
set old_dbs_out=tmp_old_exc.out
set window=14

rem Run utility to obtain the current day

%drive%\%adsm_dir%\%adsm_cmds%\getday.exe

if errorlevel 7 goto IncrBackup    ;Sat
if errorlevel 6 goto IncrBackup    ;Fri
if errorlevel 5 goto IncrBackup    ;Thu
if errorlevel 4 goto IncrBackup    ;Wed
if errorlevel 3 goto IncrBackup    ;Tue
if errorlevel 2 goto IncrBackup    ;Mon
if errorlevel 1 goto FullBackup    ;Sun

:IncrBackup
echo Starting the Exchange Database backups on %computername% now >>
%backuplog%

CD /d %drive%\%adsm_dir%\%adsm_exc%

rem Do an incremental backup of the Directory and Information Store
Exchange
Databases

excdsmc /backup:dir,incr /logfile:%backuplog%
excdsmc /backup:is,incr /logfile:%backuplog%
goto exit

:FullBackup
echo Starting the Exchange Database backups on %computername% now >>
%backuplog%

CD /d %drive%\%adsm_dir%\%adsm_exc%

rem Do a full backup of the Directory and Information Store Exchange
Databases

excdsmc /backup:dir,full /logfile:%backuplog%
excdsmc /backup:is,full /logfile:%backuplog%

:ADSMCleanup
rem Clean up old databases

echo Removing old databases from the ADSM Server >> %backuplog%

rem Get the list of old Exchange databases
rem on the ADSM Server via the perl script below

excdsmc /adsmquerydb > %old_dbs_in%

perl %old_dbs% %window% %old_dbs_in% %old_dbs_out%

for /f %%i in (%old_dbs_out%) do excdsmc /adsmdelete:%%i
/logfile:%backuplog%

:exit
echo Backup script has finished >> %backuplog%

exit
=========================================================
=========================================================
File:GETDAY.EXE
---------------
*** NOT INCLUDED IN-LINE
*** NOT INCLUDED IN-LINE

=========================================================
=========================================================
File: exc_list_old_dbs.pl
-------------------------
#!perl.exe
#!perl.exe
#
# exc_list_old_dbs.pl
#
# This script generates a list of exchange databases which are
# greater than $ARGV[0] days old and writes them to a temporary file

# allow window to be specified as a parameter

if ($ARGV[0]) { $w=$ARGV[0]; } else { $w=7; }

$start=0;

open (OUT,">$ARGV[2]") || die "ERROR: can't open \$ARGv[2] \n";
open (IN,"$ARGV[1]");

# evaluate 7 days ago date string

@days=(31,28,31,30,31,30,31,31,30,31,30,31);
(@now)=localtime(time);

# check numbers for 0 padding and millenium

if ( $now[5] =~ /^9[89]$/ ) { $now[5]=~s/^/19/; }
elsif ($now[5] =~ /^[0..9][0..7]$/) { $now[5]=~s/^/20/; }

# note above should be valid for 100 yrs or until the year is 4 digits

if (length($now[4]+=1)==1) { $now[4]=~s/^/0/; }
if (length($now[3])==1) { $now[3]=~s/^/0/; }

#decide if year is a leap year
# if a year is exactly divisible by 4 and NOT exactly divisible by 100
but is
divisible by 400

if (($now[5]%4==0 && $now[5]%100!=0)||($now[5]%100==0 &&
$now[5]%400==0))
    { $days[1]=29; }

# now derive 7 days ago marker

if ($now[4] == '01' && $now[3] < '07') {
 $ago7=($now[5]-1).'12'.sprintf("%02.2d",31-$w+$now[3]);
 }
elsif ($now[3] < '08') {

$ago7=$now[5].sprintf("%02d%02d",$now[4]-1,$days[$now[4]-2]-$w+$now[3]);
 }
else { $ago7=$now[5].$now[4].sprintf("%02d",$now[3]-$w); }

# process each line of adsm report and write old logs to OUT

while (<IN>) {
if (/^-----/) { $start = 1; next; }
if ($start && /^[a-zA-Z]/) {
 chop;
 (@fields)=split(/[ ]+/);
 ($m,$d,$y)=split('/',$fields[3]);
 $testnum=$y.$m.$d;
 if($testnum<$ago7) {
  $cut=join('',$fields[0],',',$fields[5],"\n");
  push(@array,$cut); }
 }
}
print OUT @array;
close OUT;
close IN;

exit 0;

# end of script
=========================================================
=========================================================

Thanks,

Del
ADSM Agent Development

=========================================================

>> Hi Phil,
>>
>> This sounds good, but you say you have enclosed the scripts?
>> Did you really or did you accidently forget to enclose them?
>>
>> Thanks
>> Christo


Gogineni



> -----Original Message-----
> From: Kauffman, Tom [SMTP:KauffmanT AT NIBCO DOT COM]
> Sent: Monday, June 29, 1998 6:57 AM
> To:   ADSM-L AT VM.MARIST DOT EDU
> Subject:      MS-Exchange agent -- backup deletion
>
> Is there any way to automatically delete previous exchange backups
> created
> with this agent? From past experience, I know full well that our staff
> will
> NEVER delete old backups manually. I need to be able to delete
> anything over
> five days old.
>
> If we can't do it automatically, is there a way in ADSM version 3 for
> an
> administrator to delete *selected* client backups?
>
> TIA
>
> Tom Kauffman
> kauffmant AT nibco DOT com
<Prev in Thread] Current Thread [Next in Thread>