Copyright Michael Karbo, Denmark, Europe.


  • Next chapter.
  • Previous chapter.


    Chapter 22. The daily backup

    I have now described what security copying is. But how should the copying be done in practice? Here are several options:

  • By using a backup program.

  • With a File manager program like Windows Explorer or Total Commander.

  • With the XCOPY command in a script on the desktop (only works with Windows XP Professional).

    There are a lot of backup programs on the market. It can be a good solution to use one of these programs - especially if you make security copies for a magnetic tape unit. In my opinion they are not well-suited for hard disk copying.

    It is easy to make a manual security copy with a tool like Windows Explorer or (better still) Total Commander. You can just drag all the files from one folder to another. But for daily security copying the XCOPY command is by far the most flexible tool.

    Use XCOPY

    XCOPY is a command, which can be run in a command window or in a little script. The command is smart because it can be designed to copy certain files and folders just as we want it to. Unfortunately, these scripts don't seem to work in the Home version of Windows XP. So this is a good reason for ensuring that you have Windows XP in the version Professional!

    I am going to show here how you can design a backup script, which can run from your desktop daily. And thus daily backup is solved! To be able to use the system, you have to (in addition to having the right version of Windows XP) have the following things ready:

  • Your mail data placed in the folder D:\Mail.

  • All the other documents gathered in the folder D:\Texts.

  • There must be enough room on the C drive for a copy of all of it.

    When these things are in place, then it is the easiest thing to make daily backup. So let's get going.

    The first script with XCOPY

    You are going to create a little script with two XCOPY commands, which will see to the copying of the files. First, we are going to make a total copy of all the user data; afterwards the script will copy all the files that have been modified since the last time.

    Now we are going to create the script so that it (hopefully) works. Later there is a description of how you can experiment with scripts in order to get a better understanding of the system.

    1.    First create a batch file, as described on page 39.

    2.    The file should be called Back.bat, and it should be placed on the desktop. When the file is open in Note pad, you type in this command:

    xcopy d:\mail\*.* d:\texts\mail\*.* /s/v/r/y

    3.    This is what it looks like (so that there is no doubt):

    4.    Save the file now with Ctl+s, and let it stay open on the screen.

    5.    Type Windows+d to minimise all the windows. The file Back.bat can be seen on the desktop:

    6.    Double click on the file; and the script runs.

    7.    All the files are copies from the folder D:\Mail to the copy folder D:\Texts\Mail. Everything happens quickly in a command window, so you probably didn't see it. If the folder D:\Texts\Mail doesn't already exist, then it will be automatically created.

    Figure 114. All the post data is security copied.

    Continuing with the script

    You have made the first security copy, but you are not finished yet.

    1.    Activate the window, where the file Back.bat can be seen in Note pad.

    2.    Enter the command:

    xcopy d:\ texts \*.* c:\textback\*.* /s/v/r/y

    3.    Save the batch file again, and test it by double clicking on its icon on the desktop.

    4.    First remake the copying you have just done as the entire folder D:\Mail is copied into the folder D:\Texts.

    5.    Then the entire content of the folder D:\Texts is copied with its subfolders into the C drive, where the folder Textback as well as the subfolders is automatically created, if they don't already exist.

    6.    If many gigabytes of data have been saved in D:\Texts, as is often the case, then it can take a long time to copy all of it.

    7.    Please remember that if you double click once on the script Back.bat, then the two copying routines will run again. Try it.

    8.    For daily use it is only necessary to copy the files, which have been altered since the last security copies have been made. Add, therefore, the parameter /m at the end of both commands.

    9.    Save the script for the last time and close the file. Try now running the script from the desktop. This time no files are copied! The reason is that they haven't been altered since they were last copied.

    Now you have a well-functioning backup script placed on your desktop. When you have been working on your computer and have saved new documents, photos, etc. in the folder structure, then you just have to run the script. And all the new files are copied for C:\Textback, which in this way is a reflection of D:\Texts. It couldn't be any easier!

    Explanation of XCOPY

    The XCOPY command is a very strong tool, as it can be adapted in a great number of ways. To be able to understand the command we should look at the four 'sections' which are featured in a command bar. The command's name is first typed in followed by the source folder. This is the folder from which the file is to be copied.

    The third section describes the destination folder, which is the recipient of all the copies.

    Finally it is possible to add parameters to the command, which will control the copying. In our case we use the parameters /s/v/r/y/m, which, among other things, ensure that all the subfolders are also copied.

    Figure 115. The command's structure.

    With the parameter /m only files with the attribute file are copied. This file attribute is activated (put on), when you, for example, open and save a Word document.

    The next time the script is run, XCOPY registers that the file attribute is activated in the file in question, which is, therefore, copied. At the same time the attribute is deactivated so that the file isn't copied the next time. Unless the file has been altered in the intervening period.

    Parameter

    Meaning

    /A

    Copies only files that have their attributes set, but does not modify the attribute.

    /C

    Continues copying even if there are errors.

    /M

    Copies only files that have their attributes set. Turns off the attributes afterwards.

    /R

    Copies read-only files.

    /S

    Copies all subfolders.

    /V

    Verifies (compares with the original) each new file.

    /Y

    Overwrites existing destination files.

    Figure 116. XCOPY commands can be adapted for a large number of conditions, so you can design exactly the copy routine you want.

    The idea of this review is that you can start designing your own small scripts. You can involve other folders in the copy routine and you can design several variations of the script.


  • Next chapter.
  • Previous chapter.


  • Book overview.