and batch files
May 31, 2009
I. Why use xcopy and batch files for backups?
II. Using xcopy
III. Batch Files
IV. Creating a log file
V. Automating Backups
VI. Additional Notes
A. Video Guide
and batch files for backups?
You will be
reading how to create a batch file using xcopy to
backup files on your computer. It will detail an explanation of
and a batch file are. You will be guided through creating a batch
file that when run will copy files from folders you have selected from
your PC to an external media, how to have this backup run on startup
and login, how to schedule it to run regularly, and creating a log file
after each backup.
The target audience for this is desktop techs and tech enthusiasts.
There's a lot to take into consideration when assessing backup
needs. This method is not suitable for all scenarios.
This can be used on just about any Windows computer.
The backup that will be detailed here is a single full backup from
selected locations on you computer to an external drive. This
will serve the purpose of keeping an additional copy of vital data in
the event of data loss of your original files. This backup method
is not ideal for backing up entire systems, keeping track and
monitoring several backups, and there are no incremental or
There are some benefits to this method of backing up over more
comprehensive solutions. It does not cost money or require
additional software beyond what is available on every Windows PC.
It requires very little technical knowledge to setup. It requires
very little technical knowledge for users. Because this only
performs the most basic of backup functions, it is very simple for
users to understand and backed up files are easily accessible.
xcopy is a
command that allows you to copy files from one location to
another. You can use the xcopy
command in the Command Prompt.
Access the Command Prompt:
Start > All Programs > Accessories > Command Prompt
At the Command Prompt, you now enter the xcopy
requires two parameters: what you wish to copy and where you want to
copy it to. So using xcopy, you
would enter something like this:
In this example, you would be copying the contents of folder1 to folder2.
You can change the way xcopy works
by adding switches to the command. Switches are options that tell
to do something different in the way it copies files. Below is
the previous example of xcopy with
"c:\folder2" /E /V /C /Y /F
In the below table, you will see eight switches that we will be using.
subfolder, even if it is empty.
each new file.
copying even if erors occur.
existing files without prompting you.
full source and desitnation file names while copying
copying of encrypted files to destination that does not support
hidden and system files.
Using xcopy, we
can backup our files to another location. However, it would be
cumbersom to have to type out the whole command, parameters, and
switches every time we wanted to backup. This is where batch
come into the picture. A batch file is a text document that
contains the commands we wish to execute. So instead of typing
out one or several long commands, they can all be typed into a single
batch file and run by double-clicking an icon.
We will be making a batch file using Notepad. Open Notepad from
the following location:
Start > All Programs > Accessories > Notepad
Once Notepad is open, enter in the xcopy
command that will be performing our backup. At this stage, we
will assume you want to backup a folder on your C: drive
to a folder on your F: drive
The below image shows Notepad with our entire command written out.
If you have other folders that you'd need backed up, you could enter a
command on a new line in the batch file we are creating.
A typical text document in Notepad will have a file extension of .txt.
In order to create a batch file, we will save our file in Notepad with
the extension .bat.
Save the file. We can save it to our Desktop and call it Backup.bat.
Now that we have
our batch file created, anytime we double-click to run the fie, it will
backup the folder(s) we selected.
Creating a log file
using the /C
switch will tell xcopy to
continue copying even if an error occurs. This is one reason why
we can benefit from creating a log file that will detail the activity
of our backup.
Also recall the /F switch, which tells xcopy to display the full source
and destination while copying. This would typically be shown
within the Command Prompt window. However, we can redirect that
output to a file. We will make a very simple addition to our
previous example. The addition is shown in bold below:
"F:\backup" /E /V /C /Y /F >
This will create a text file called backuplog.txt.
After running our backup, we will be able access this file and confirm
every file has been copied and see any errors that may have occurred.
With our Backup.bat
file saved to the Desktop, the user can manually perform a backup by
running the file. This is particularly useful for users that want
to perform a backup after saving an important file. However, we
can also make these backups run regularly (daily, weekly, monthly, etc)
or even to run the backup every time the user logs in.
There is a special folder in Windows. Any files, shortcuts, or
applications that are placed in it will run when the user logs
in. The folder is located here:
Start > All Programs > Startup
If you place a copy or shortcut of the Backup.bat
in the Startup folder, the backup will run every time the computer
starts up. There are two noteworthy potential disadvantages to
this. If there is a lot of files to backup, it may take awhile to
complete upon login, which may bother some users. And the user
may not have backups occurring frequently enough if they rarely log in
and out of the computer.
The second option is to schedule the backup to run regularly.
This can be performed using Scheduled Tasks which you can access here:
Start > All Programs > Accessories > System Tools >
Here you can add a task to be performed regularly.
Always keep the user in mind and what's best for them. One of the
benefits of this method is it's very easy for the user to understand.
Ultimateley, you'll have to make the assessment of what is the ideal
backup solution for a given situation. Although not a feature
rich solution, the simplicity can actually be a strength. Many
users are confused with "what's actually being backed up" and how to
retrieve backed up files. With this solution, were a user to be
backing up to an external flash drive, they would be able to easily
remove it and place it in a fire proof safe. Or were their
computer to break, they could take the flash drive to another computer
and immediately access their files.
Although a disadvantage in having fewer backups, the simplicity of
having only one full backup is much easier to explain to a user.
Explaining to an end-user the difference between full, differential,
and incremental backups and telling them about the
Grandfather-Father-Son backup rotation, or shadow copies in Windows can
be very confusing to end-users, may even scare some away from backups,
and can be overkill for many situations.
If you have any
comments or questions, please contact me at AdamGabeLowe [a] gmail.com.
Copyright 2009, Adam G. Lowe