Stuart_C Posted October 2, 2012 Posted October 2, 2012 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?
mattx Posted October 2, 2012 Posted October 2, 2012 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. 1
jinnantonnixx Posted October 2, 2012 Posted October 2, 2012 (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 October 2, 2012 by jinnantonnixx 1
Stuart_C Posted October 18, 2012 Author Posted October 18, 2012 Thanks @jinnantonnixx I'll give that a go.
jinnantonnixx Posted October 18, 2012 Posted October 18, 2012 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now