So I have been playing with batch files recently and have discovered their amazing awesomeness. I decided to share what I have learned in a series of posts where I simply just post my code.
PLEASE NOTE I AM NOT AN EXPERT. This works and is easy to do. Use at your own risk, ask any questions in the comments I will answer the best I can.
First one is a simple back up .bat.
xcopy “STARTING DIRECTORY” “DESTINATION DIRECTORY” /D /E /C /R /I /K /Y
It’s that simple.
What this does is copies the STARTING directory to the DESTINATION directory, only copies files with a newer modified date and keeps the folder structure.
Here is an example with the directory paths put in:
xcopy “c:My Files” “d:My Files Backup” /D /E /C /R /I /K /Y
As you can see your path can be to any drive on your computer, even a networked mapped drive.
Let’s say you are on a network and you want to backup to a drive on your server (or any other computer) but that drive is not networked. No problem, you can use the UNC path.
xcopy “c:My Files” “\SERVER NAMEHARD DRIVE SHARED NAMEMy Files Backup” /D /E /C /R /I /K /Y
Notice it asks for the HARD DRIVE SHARE NAME, this is the name the drive was given when it was shared out to the network.
NOTE: This will just back up your file structure into a new file structure that matches on your separate drive. Basically what it does is sync the two locations. If you run this .bat file again after you have changed some files or added some files, it will ONLY copy those changed and moved files to your backup location.
This is a very simple backup utility that will copy new files to your back up location. Next time I will go over redundant backing up with zip files and version dates.