Jump to content

Ntbackup Batch File Help


Recommended Posts

Hi guys,

Not sure whether i landed in the right forum, but i will try anyway:

We have a backup script that runs daily and performs different backup tasks with NtBackup.

There is a remote site with a DC in it on which we want to backup the system state+several folders to a local disk.

What i need to insert in a script is some sort of "If, then" line, which will delete the old copies of the .bkf files, up to 3 days back.

Thus, if a backup was performed on 20-th of the month, i want the script to delete all previos .bkf files and will leave only the last 3 backups, from 17,18,19 of the month.

Does anyone have any clue what is the syntax i should use to perform such operation?

I'm quite clueless when it comes to scripts :unsure: .

Any help would be highly appreciated,

Thanx! :hello:

Link to comment
Share on other sites


(Note: Post has been editted (updated)

Post your current script to see what there is to work with.

There are many ways to accomplish the same thing. I would start by naming the backup files by date, or day (1.bkf - 31.bkf etc). Then rename the 3 you want to keep while you delete the rest.

One way to do it...

A small example:

set name=%date:~7,2%
ntbackup backup systemstate /j "Command Line Backup 4" /f "c:\backups\%name%.bkf"
if %name% == 20 goto _delold

exit

:_delold
if exist c:\backups\17.bkf ren c:\backups\17.bkf bkf.17
if exist c:\backups\18.bkf ren c:\backups\18.bkf bkf.18
if exist c:\backups\19.bkf ren c:\backups\19.bkf bkf.19
if exist c:\backups\20.bkf ren c:\backups\20.bkf bkf.20

del c:\backups\*.bkf
if exist c:\backups\bkf.17 ren c:\backups\bkf.17 old17.bkf
if exist c:\backups\bkf.18 ren c:\backups\bkf.18 old18.bkf
if exist c:\backups\bkf.19 ren c:\backups\bkf.19 old19.bkf
if exist c:\backups\bkf.20 ren c:\backups\bkf.20 old20.bkf

exit

By renaming them with the "old" prefix, they will be deleted next month along with all other bkf files, and there will be no overwrite problem with the next months files named 17, 18, 19 .bkf

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...