Do you find yourself needing to copy or move a bunch of files on a regular basis as part of an archiving or backup process, but find that it’s too manual or you need special software? The solution I came up with involves ROBOCOPY, which is included in Windows 7 and Windows Server (2008, 2012, and in the Resource Kit of Server 2003). In fact, if you download it manually it’ll even work on Windows XP and Vista.
The beauty of ROBOCOPY is it’s simplicity. It’s a command line tool that you can throw into a batch file and then schedule using Windows Server’s Task Scheduler. I schedule ours to run every Friday night, and it makes a backup of all the files we have stored on our network by Dropbox. I also have another one which goes through every month and archives any files that haven’t been accessed for more than 2 years.
There are plenty of articles online about how to configure ROBOCOPY but after I’d read them all I was still struggling with one final issue. Instead of overwriting the same backup location every time, or even mirroring the data to there, I wanted it to be able to backup to a fresh location every time but I didn’t want to have to specify it manually. In other words, I needed variable parameters that created a folder based on the date of the backup. This is the solution I finally found:
robocopy “serverdataDropbox” “server2backupsDropboxBackup%date:~10,4%%date:~7,2%%date:~4,2%” /MIR
The date variables are not a special feature of Robocopy – they’re just a system variable that you can get and feed into any command-line operation. Try going to a command line now and type in:
You should get something that looks like this:
When you put %date:~6,4% it ignores the first 6 character and then returns the next 4. If your first character is -6, then it will start 6 characters in from the right side rather than the left.
However, the format varies depending on your region, so the command line script you create may be different in Australia compared to if you’re in the US.
In my case, I took the above Robocopy command, saved it in a batch file on the server, and scheduled a task to run according to my required schedule. Voila!
Tags: archiving, automate, backup, robocopy