Hot To: Write a Batch file for Simple Back Up 2

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.

@echo off

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:

@echo off
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.

@echo off
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.

Leave a comment

Your email address will not be published. Required fields are marked *

2 thoughts on “Hot To: Write a Batch file for Simple Back Up

    • The Revenge Post author

      something you loser mac users wouldn’t know shit about!

      actually i think you can use them…or a form of them on a MAC.

      Basically it’s a old school dos coding which allows you to do almost anything with a small text file.

      Like at work I’ve written a series of batch files with menus that have taken an installation process for our software from about a day to install everything down to about 10 minutes for a full install.

      extremely powerful stuff and the easy back up runs incredibly fast and allows the person writing it to control everything, assuming they pay attention to what they are writing.