Jump to content

Recommended Posts

Posted

Hi there,

 

I need some scripting help please.

 

Every day one of the database servers backs up the databse files to disk (on the server). The files are stored in folders called Daily_YYYY_MM_DD_2300 and it creates 7, one for each day of the week, and then overwites the oldest so I always have 7 folders.

 

However I need to back them up to external storage somehow. I wanted to avoid having to delete and re-copy all the files due to slow network speeds. Basically I need to copy the newest backup folder from the source and delete the oldesst backup folder on the destination.

 

any ideas?

Posted

In the batch file delete the previous backup file / structure first using del, deltree or RD and then simply copy the new one into the folder.

 

del d:\backups\monday\*.backup /q

copy \\server\*.backup d:\monday

 

Or delete the files from the backup source once copied over.

  • Thanks 1
Posted (edited)

Robocopy with the /MIR option (mirror) will delete files on the destination that do not exist on the source.

 

 

e.g. robocopy \\source\folder \\dest\folder * /mir

 

Even though you specify the * wildcard, robocopy will not bother copying files that already exist on the destination.

 

Robocopy | SS64.com

 

 

/MIR : MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E)

/PURGE : Delete dest files/folders that no longer exist in source.

Edited by jinnantonnixx
  • Thanks 1
  • 3 weeks later...
Posted

Be careful - as with any powerful tool things can go wrong. The /MIR will delete everything that exists in the target that does not exist on the source.

 

When testing, you might want to try the /L option, which does a dry run, without doing anything useful (or destructive).

/L : List only - don’t copy, timestamp or delete any files.

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



×
×
  • Create New...