1.

Solve : Batch job that send out email and deletes previous backup?

Answer»

I have written a working batch file to back up some folders/application

echo off

echo call batch job

CALL PCSDEV.bat  (This is where the backup get executed)


echo return from backup to the current calling batch file
REM Change directory back to the location where the file is archived
d:
REM cd ..

cd D:\IIS_ETL_BK

set HR=%time:~0,2%
set HR=%Hr: =0%
set HR=%HR: =%
ren Test.out.isx Test.out-%date:~10,4%%date:~7,2%%date:~4,2%_%HR%%time:~3,2%.isx


cd /istoolbk

My question is:

1. I want to send out email NOTIFICATION after the backup is completed=> before the last command
2. I want to check for previous 15 backup(an example), if there are 16(an example) I want to delete the first backup. In essence keeping 15 sequential backups at a time
Quote from: Great! on June 10, 2015, 05:18:55 PM

1. I want to send out email notification after the backup is completed=> before the last command
2. I want to check for previous 15 backup(an example), if there are 16(an example) I want to delete the first backup. In essence keeping 15 sequential backups at a time

There are more reliable ways to get a date and time string which do not depend on the user locale and/or MACHINE and which sort naturally in a batch script.

Some questions you'd need to answer are:

  • What is the filename FORMAT of the backup files?
  • Are there any other files in the folder with the backup files?
  • What is the NAME of the backup folder location
  • Do you have admin permissions
  • What tool do you want to send the email with?
  • What is the actual NUMBER of files being kept - a range of the actual number would be nice. 10 to 200 for example.
    What is the filename format of the backup files?
     -----
     The filename format is an application based format that ends with . A typical example is this Test.out-20151206_0953.isx

    Are there any other files in the folder with the backup files?
-----
   There will be other files from previous backup in this directory reading different timestamp

    What is the name of the backup folder location
----
   The name of the backup location is a subfolder under the folder where the script is located. SO if my script is in D:\Istool.   My backup will be D:\istool\Backup

    Do you have admin permissions
-----
 Yes

    What tool do you want to send the email with?
----
 Pure MSDOS batch command. No third party tool

    What is the actual number of files being kept - a range of the actual number would be nice. 10 to 200 for example.
---
30 meaning one backup per day Quote from: Great! on June 12, 2015, 12:53:45 PM
    What is the filename format of the backup files?
     -----
     The filename format is an application based format that ends with <FileName-TimeAdded.isx>. A typical example is this Test.out-20151206_0953.isx

You use YYYYDDMM format ? 

Quote from: Great! on June 12, 2015, 12:53:45 PM
    Are there any other files in the folder with the backup files?
-----
   There will be other files from previous backup in this directory reading different timestamp

Are there only .isx files in the backup folder?  One per backup?


Quote
    What tool do you want to send the email with?
----
 Pure MSDOS batch command. No third party tool

There's a problem there.  No pure MSDOS batch command exists, to send an email."You use YYYYDDMM format "? 

-Yes appended to the file


"Are there only .isx files in the backup folder?  One per backup?"

-Yes Only .isx file

"What tool do you want to send the email with?"

-What options available here
Here's a snippet that will keep the 30 newest files in the backup folder that is in the current folder.

Remove the echo after testing.  It will simply echo the delete commands to the console at the moment.

Code: [Select]echo off
for /f "skip=30 delims=" %%a in ('dir backup /b /o-d /a-d') do echo del "backup\%%a"
pause

A VBS script has the ability to send email
sendmail, blat, and others are free email sending tools.



Discussion

No Comment Found