The Infinite Loop – Beginner's SEO, Beginner C# & JQuery Tutorials Problem. Problem Solved. Loop. – The life of a programmer

14May/090

USB Backup Utility with Batches

After my USB got FRIED behind the damn photocopier in the library a couple years ago, I had to re-do my whole Java Assignment AGAIN. I decided to make a little backup utility that would make it a little easier to back up my usb. It will only work if the pen drive is a fixed letter, but its always E: on my computer so thats fine by me. It consists on 2 files placed on the usb, a backup.bat that does the backing up and an autorun.inf which puts the Backup option into the autorun screen. When i plug my USB pen drive, the autorun gives me the option to backup, making an exact copy of my usb at c:/usb

Open notepad and paste this text in.

@echo off
echo USB BACKUP UTILITY V1.0
echo CREATED BY SCOTT
echo ----------------------------------------------------------
echo Starting Backup:
cd \
c:

if exist c:\usb goto exists
mkdir "USB"
goto copy

:exists
rmdir "USB" /s /q
mkdir "USB"

:copy
echo Date>C:\usb\backup.txt
date /t>>C:\usb\backup.txt
echo.>>C:\usb\backup.txt
echo Time>>C:\usb\backup.txt
time /t>>C:\usb\backup.txt
echo ------------------------------------------->>C:\usb\backup.txt

cd \
xcopy E:\* "C:\USB" /y /e /r /v>>C:\usb\backup.txt
echo Backup Complete!
echo.
echo Backup of entire USB at C:/USB
echo Log file placed at C:/USB/backup.txt
echo ----------------------------------------------------------
Pause

In the line xcopy E:\* "C:\USB" /y /e /r /v>>C:\usb\backup.txt, replace E: in this line with your actual drive letter.
Save this file as backup.bat making sure that "All Files" is selected from the files drop down box.


Next repeat the same steps, saving this text as autorun.inf

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

Save both these files on the root of your USB.
The next time you plug your usb in, you will see the autorun option "backup".
By clicking this and hitting ok, a full usb backup will be performed and put in C:/USB