The Globecast Network    |    The Globecast  Live Sail Die  Sandstorming   Messquoted  The Trailer Mash  Arcade Center  Shipping Database  Sailing Photos

Backup USB Drive on Insertion

June 12th, 2006 at 9:02 pm By johnsee (Gadgets, Features, Tech & Science)

I use my USB drive for everything. It runs Portable Firefox, Portable Thunderbird and also holds most of my files. While it’s great having these programs run no matter where I am, frequently backing up the data is a pain. I wanted an automatic solution. Unable to find a good solution on the net, I created one for myself.

Step 1: Create the folder you want to backup to (Mines c:\removablebackup)
Step 2: Create the backup batch file for your USB key. You can do this by inserting the following in a textfile and saving it as backup.bat. An example is provided below:

@echo off
echo -------------------
echo Removable Device Automatic Backup
echo -------------------
echo No Rights Reserved, do whatever you want with this.
xcopy "*" "c:\removablebackup\" /Y /E /R
echo Backup Complete!
Pause.

Make sure you change the section in bold to reflect your individual backup location.

Step 3: Place the following in a text document, and save it directly to your removable drive as autorun.inf:

[autorun]
action=Backup
open=backup.bat
label=Backup
includeRuntimeComponents=True

Step 4: Your done! Now whenever you insert your USB key you should see this nifty backup option:

backup.png

26 Comments

  1. dan said,

    June 12, 2006 at 10:31 pm

    yah, i did that once, then i kinda formatted my usb key.. lol

  2. mike said,

    June 22, 2006 at 7:22 pm

    Wow, you have no idea what you just saved me from buying. Thank you.

    I was trying to do the reverse: use usb keys instead of tapes for backups. So I wanted to copy from my hard drive to the USB stick. In case anyone else is interested, here’s what I did:

    1. Clear out the USB key.
    2. Make a folder (I called it “storage”) on the usb key.
    3. Put the autorun.inf file on the usb key. The contents are the same as above.
    4. Put the backup.bat file on the usb key. The contents are as follows:

    @echo off
    echo ——————————-
    echo Removable Device Automatic Backup
    echo ——————————-
    echo
    xcopy “c:\FolderIWantToBackUp” “\storage” /Y /E /R
    echo Backup Complete!
    Pause.

    you can customize the xcopy options - just google for “xcopy”
    the “\storage” path is, of course, relative to the USB key.

    Again, thanks to Johnsee for the inspiration.

    Quick question, though: my “@echo off” command will still output “ECHO is off” to the console. The @ is supposed to suppress this, right? Does anyone know why it wouldn’t be doing this?

  3. mike said,

    June 22, 2006 at 8:04 pm

    I just realized, it may be wise to put a command to clear out the destination before writing to it. In case the source has had a file deleted, it won’t be present in the backup. I added the following line right before the xcopy command

    “rd /s /q “\backup”

    Also: I solved the “ECHO is off” problem. Typing a period immediately following a blank echo command will output a blank line (like I wanted), instead of an “ECHO is off” message. So, all my echo statements now are:

    echo.

    with a period right after it.

  4. Girish said,

    July 7, 2006 at 8:00 pm

    Hi,

    i am not able to take backup, when i inserted my USB (U3)

    i have followd same steps as given above, so help me out.

  5. How to Automatically Backup your USB Drive on Insertion at Shivaranjan’s Blog said,

    July 8, 2006 at 2:43 am

    […] Many of us are using USB drives these days as the prices have fallen down. If you use your jump drives regularly then you might want to backup the data in it automatically. I came across this article by Sandstorming.com on how to automatically backup your pen drive when you insert it. […]

  6. Jestre said,

    July 26, 2006 at 1:29 am

    Since 7 zip is portable try the following for smaller sequential backups:
    NOTE: it creates a new backup file everyday but try setting system date format to YYYY-MM-DD format so it will sort.
    It then creates a file name of Firefox.dat.2006-07-25.7z etc.

    Del “\Data\Firefox.dat\XUL.mfl”
    Del “\Data\T-Bird.dat\XUL.mfl”
    \Apps\7-Zip\7z a -r “C:\Backups\Firefox.dat.%date%.7z” “\Data\Firefox.dat”
    \Apps\7-Zip\7z a -r “C:\Backups\T-Bird.dat.%date%.7z” “\Data\T-Bird.dat”
    \Apps\7-Zip\7z a -r “C:\Backups\Personal.%date%.7z” “\Personal”

  7. zuper said,

    August 26, 2006 at 6:14 pm

    i’ve added a /D to the xcopy command,

    so it backs up only the files modified ;)

  8. zuper said,

    August 26, 2006 at 6:30 pm

    i’ve also created a log file, so you always know what happened..

    and so you can clear the pause command…

    date /t>>backup.txt
    time /t>>backup.txt
    xcopy “*” “c:\removablebackup\” /Y /E /R /D>>backup.txt
    echo ———————————————–>>backup.txt

  9. Dan W. said,

    September 10, 2006 at 11:10 pm

    Hey Johnsee, you thu MAN…………………………………works great and a complete solution to my problem which was the same as your problem. I did add the RD command to my .bat file to clean up my backup folder but thanks for taking the time to post.

  10. Liam said,

    September 20, 2006 at 9:55 am

    I have added a few commands from the original

    @echo off
    echo ———————————
    echo Removable Device Automatic Backup
    echo ———————————
    echo Backing Up Data
    date /t>>backup.txt
    time /t>>backup.txt
    xcopy “*” “c:\removablebackup\” /e /y /r /h /d>>backup.txt
    echo Backup Complete!
    Pause.

    howevery when i try to backup my USB drive i keep getting a share violation issue and its always on the same file. Is there a way i can make it skip and share violations or is there a way i can fix it? Can anyone help?

  11. Jaap said,

    October 4, 2006 at 11:25 pm

    This little thing is just what I need! But I have a little problem.

    Whenever I try the option ‘backup using the program provided on the device’ I get the error that ‘F:\ is not a valid win32 application’. For every other task the stick is functioning perfectly. When I run the xcopy command from the command prompt the files are copied as expected.

    Can someone help me out?

  12. Jaap said,

    October 5, 2006 at 2:11 am

    Thanks if you’re thinking about my head-breaking problem, but the solution was very simple but stupid also. I named my file ‘backup.dat’ in stead of ‘backup.bat’.

    Thanks again for this powerful tool!

  13. Jason said,

    October 28, 2006 at 1:10 am

    Hey thanks guys,
    I am using USB backup mode #2 (backing up from C: drive to USB key), which works great.
    I am actually trying something a little more advanced now, backing up from a network drive to USB key), which I am having some difficulties with, as when the XCOPY command is used, it seems to forget where the key is (drive letter-wise) and is actually copying the network drive to my C: drive instead.

    (I should mention to, that rather than having the key “Auto-update by itself” I have the USB key open a webpage that I built to help navigate the key folders. Then on the main page, I have a link to “Update key”)

    Has anyone else tried this?
    Thanks again for this cool app.

    J

  14. Andrew said,

    November 8, 2006 at 12:12 am

    Hello,
    iI found very good what Jestre said.
    Could you tell me how to set system date format to YYYY-MM-DD
    using batch command?

  15. belief said,

    August 16, 2007 at 6:05 pm

    I suggest programmers to write simple file to sync flash drive with a microsoft briefcase in hdd. the point is briefcase is use for synchronisation, it does better than pure backup which doesnt address delete.

  16. Vikrant Rampuria said,

    August 23, 2007 at 9:02 pm

    Hello
    I want my data to be backed up with to my USB drive with regular interval of time. For instance i save all my data to one folder and i want somethng which can auto backup data with a interval of 5 or 10 mins.. Is it possible or not … Can anyone help me ???

  17. steve said,

    September 10, 2007 at 12:25 pm

    I really dont understand about programing. Could anyone make an .exe program of it. I really appreciated. Thank You

  18. Ed M said,

    November 9, 2007 at 7:31 pm

    Great! really works! Thank you.

  19. homer said,

    November 12, 2007 at 1:56 pm

    Ingenious, now all that is left is removing files that have been deleted from the source folders

  20. divad said,

    November 13, 2007 at 8:38 pm

    hi …

    I want to know how I can make a automaticaly backup when the usb flash disk plug to the computer without asking me if i want or not….

  21. meridia online said,

    December 15, 2007 at 4:13 pm

    meridia

    encrusting discussed

  22. Michael said,

    March 17, 2008 at 4:10 am

    how do you make the program delete things in the backup folder that have been deleted on the flash drive?

  23. Anon said,

    April 11, 2008 at 4:08 am

    “how do you make the program delete things in the backup folder that have been deleted on the flash drive?”

    Use robocopy and the /mir option. Not only is it more reliable than xcopy but it has a 22 page manual full of options you can use. It can be obtained with the resource kit tools from microsoft. You’ll have to keep the exe on your usb drive but it’s 78 KB. If you have vista you already have it just type robocopy /? in a command shell.

  24. Brad said,

    May 21, 2008 at 6:24 pm

    I had it working (2nd method….backing up from C:\ to USB drive), and after I was playing around with making some of the files hidden (autorun.inf, backup.bat, icon file, robocopy.exe) I’m getting the error message: F:\ Access is denied

    Any ideas? I appreciate any help.

  25. Ken said,

    May 24, 2008 at 1:29 pm

    I had this working. Its great but instead I used winrar to archive it onto my usb. I used this batch command:

    @echo off
    echo ——————-
    echo Removable Device Automatic Backup
    echo ——————-
    “C:\Program Files\WinRAR\RAR.exe” a -r -t “BACKUP_FILE.rar” “FOLDER BEING BACKED UP” -ag[mm-dd-yyyy]
    pause

    Then I used this website’s .inf template

    resulting file will named:
    BACKUP_FILE[MM-DD-YYYY].RAR

    Hope this helps someone.

  26. Kjetil said,

    September 18, 2008 at 7:00 pm

    I have a small suggestion for a change to the script. There is always the danger of selecting backup when we are using someone elses computer. Or somewhere where you don’t want any backup. At least when you have a habit of clicking it.

    My suggestion is to create a batch file on the C: drive(s) of your computer(s) where you want the backup to run. In this batch file, you put the xcopy command.

    Then, on your USB drive, you remove the xcopy command, and instead call the batch file on C:.

    Thus, if the batch file exists on C:, your backup is made. If not, the backup will fail (which is what you want!).

Post a Comment

Trackback URL for this post: http://www.sandstorming.com/2006/06/backup-usb-drive-on-insertion/trackback/