Page 1 of 1

How to back up your files. The Batch file way Rate Topic: -----

#1 youbob1212   User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 138
  • Joined: 31-October 10

Posted 13 November 2010 - 02:46 PM

Hello people. I thought it would be nice to share with you on how to back up your files and personal data automatically.

(a place to back up your stuff)
First thing you need is a thumb drive. In my case I use an external hard drive that uses USB for a connection.

Make one folder on your desktop called "test".
Outside of that folder you will create a simple batch file.
Right click anywhere on your desktop, and put in a new text file.

Put this code in it.
@echo off 

set drive=E:\fullback
set backup=xcopy /s /c /d /e /h /i /r /y

echo backing up now....

%backup% "%userprofile%\Desktop\test" "%drive%\"


Save it as a .bat file. I call minds backup.bat.

Before we can run this program we need to edit a few things.

set drive=E:\fullback

In this line of code change the E: to whatever drive letter that your USB Thumb Drive is called. What it does is set drive variable to equal E:\fullback

The word fullback is just the name of your backup folder. You can change this to anything you want.

set backup=xcopy /s /c /d /e /h /i /r /y

This is the heart of our code. I'll explain later.

echo backing up now....

%backup% "%userprofile%\Desktop\test" "%drive%\"

Once the two variables have been set, it's now time to put them to work. What we want the program to do is make a new folder called fullback in our backup drive(inside of E). Next we want to take files that are in our test folder and xcopy them to fullback.
%backup% "%userprofile%\Desktop\test" "%drive%\"

However, we need to make this process smarter. So once you copy those files in your folder, the program will not recopy them again, Unless you change that file. This batch file will move hidden files, read only files, and simply will just replace old files( that the time index has been changed) with new file, even if they are the same name. Also it will replace file with the same name if the size of the file has been

That's all to it.. Now for a bonus we need to make this thing execute when we start up the machine.

Go to start, run, and type in regedit.
called "HKEY_LOCAL_MACHINE" and HKCU for for the hive "HKEY_CURRENT_USER"


While that folder is still selected, right click on the right side of the window, on a white blank area of the screen, and select new, and new string.
Call your new string backup, and double click it.
with in the value are put in the area location of your backup.bat file.
something like this.
C:\"Documents and Settings\USERNAME\Desktop\backup.bat"

You must use Parentheses.

and hit ok, and your done.

Now within your test folder Start throwing in files that you want to back up, and restart your computer or just run the program.

This tool is very powerful. You can back up your whole entire hard drive to another hard drive. And your code will be rather small, and no different than what you see here.

Is This A Good Question/Topic? 1
  • +

Page 1 of 1