The Backup Plan


This post is rather specific for windows. Perhaps later I can make a Linux equivalent.

I was planning to write something about batch files. These are small ‘programs’ you can easly write yourself by using notepad or something similar.
Batch files are actually a series of commands with are executed in a sequence.

Now, since a lot of people struggle with this for some reason, I’ll create a small batch file which will automatically make a backup of all jpg files to a specific folder. Most people are terrified of losing their pictures and would rather have some automatic way to secure their picture.

What this batch file should do is locate all the .JPG files in a folder, take a copy to another folder and just for the fun we’ll allow the end user to start the batch file manually and to enter a folder path other than the default one.

  • Step 1: Open notepad ;-)
  • Step 2: Open a command box (start >> run >> cmd)
  • Step 3: the command used to copy files in the command box is “copy”.. How convenient. Let’s try the copy command in the command box. Just to see what it does.
    In my case the folder where my pictures are at is C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures. My backup folder is C:\PictureBackup (it would be better if you copied all the pictures to another partition, remember? ;-))
    So the command we will use is COPY “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures” “C:\PictureBackup”
    Put the path between quotes, it doesn’t like spaces that much, you can prevent it from failing by doing so.
    Result:

    As you can see 4 files have been copied to my backup location.
    The command says COPY from folder A to folder B

  • Step 4: Okay, now we just want it to copy the JPG files. So all files with the extension .JPG.
    You’ll have to adjust your command as follows:
    COPY “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\*.JPG” “C:\PictureBackup”
    *.JPG means that all files with the extension JPG will be copied. * is a wildcard, it means that it doesn’t matter what it says before the .JPG
    As you can see still 4 pictures are copied. Which is great since there are 4 jpgs in that folder. But it also prompts me a question. Since the files already exist at the target location some action will need to happen.
    We’ll adjust the command in such a way that all files with the same name are overwritten automatically.
  • Step 5:  Adjust as following:
    COPY “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\*.JPG” “C:\PictureBackup” /Y
    /Y is an option for the command copy. It says, just overwrite the files with the same name
  • Step 6: Good! Now let’s put this command in the txt file. Save the txt file with name “AutomaticBKP.bat”. Make sure the extension is BAT. You can now double click the bat file and the JPGS will be copied.
  • Step 7: allowing a user to enter a source folder. And this one is a bit tricky. Right click your bat file you’ve just created and select EDIT. You can now see your commands again.
    Adjust as following:

    @ECHO OFF
    IF [%1]==[] GOTO AUTO

    :AUTO
    COPY “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\*.JPG” “C:\PictureBackup” /Y
    GOTO END

    :MAN
    COPY “%1\*.JPG” “C:\PictureBackup” /Y

    :END
    EXIT

    Looks kind of gibberish doesn’t it?
    Not so hard:

    @ECHO OFF==> All system messages will be supressed. Like the next line. It won’t be shown anymore if you run the bat file. This is optional ofcourse
    IF [%1]==[] GOTO AUTO==> This says if the first parameter (%1) is empty go to section with name AUTO.

    :MAN==> Name of a section. In this case MAN
    COPY “%1\*.JPG” “C:\PictureBackup” /Y==> same as before but the source folder is here parameter %1. I didn’t pick the name %1, it just is this way ;-). Windows will know what to do with it.
    GOTO END==> go to section with name END

    :AUTO==> Name of a section. In this case AUTO
    COPY “C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\*.JPG” “C:\PictureBackup” /Y==> no need to explain this right

    :END ==> go to section with name END
    EXIT==> Exit the bat file

    That’s it actually. Rather easy no?

  • Step 8: Good we now got our bat file. Let’s run it manually so we can enter a source folder ourselves. Use the full path of the bat file to let it run but before you hit enter, also enter the full path to the source folder where you want to copy pictures from. Like this:
    “c:\PictureBackup\AutomaticBKP.bat c:\TEMP”
    Now all JPG files from location c:\TEMP will be copied to the backup folder.
  • Step 9: ofcourse we want to automate the backups, so we need to schedule a task. Click start >> accessories >> system tools >> scheduled tasks. Follow the GUI here to define when the task should run. As program you need to enter your bat file.
    Define it for example to run each week. If you computer is powed on, the task will automatically copy all JPG files from the default picture source location to the backup folder.

I understand that this may seem a bit hard. But really it is rather easy.

let me know if you have some questions!

Advertisements

One thought on “The Backup Plan

  1. Pingback: Old Skool Computing « Tech-o-rama

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: