Just created a Backup batch file but need some help?

Associate
Joined
28 Dec 2002
Posts
2,400
Location
Northern Ireland
This is the Batch File i have created however i always keep some files on my desktop that i would like to backup using this bathc file.

I have inserted a line to backup the desktop but it doesnt copy any files or folders???

Im stumped can anyone help me out???

@Echo off
:: variables
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y /h

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"

:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

echo Backup Complete!
@pause
 
2 seconds just checking the batch file again,...
 
Last edited by a moderator:
Try running without @Echo off at the start so you can debug it.

I'd imagine copying a whole drive would be possible using the /E switch. i.e.

xcopy /E e:\ <destination>
 
Last edited:
This is great guys thanks going to try this out now

HangTime said:
Try running without @echo off at the start so you can debug it.

I'd imagine copying a whole drive would be possible using the /E switch. i.e.

xcopy /E e:\ <destination>

any other info on how i get it to run when i log off or shutdown
 
ace2109 said:
This is great guys thanks going to try this out now

any other info on how i get it to run when i log off or shutdown

Create a shutdown .bat file which does the copying and then shutsdown the pc from the command line. So to backup and shutdown you would just double click an icon on the desktop.
 
cheer sthats great

however still cant get the file to backup my whole E drive.

New code:

@Echo off
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up Data Drive - May take several minutes...
xcopy /E e:\Data Drive

echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"

echo Backup Complete!
@exit
 
ace2109 said:
cheer sthats great

however still cant get the file to backup my whole E drive.

New code:

@echo off
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up Data Drive - May take several minutes...
xcopy /E e:\Data Drive

echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"

echo Backup Complete!
@exit

Try this

Code:
xcopy /Q /Y /E /I e:\* c:\Backup E Drive
 
Still a no go mate, get the following coming up

****** Complete System Backup ******
### Backing up My Documents...
### Backing up Desktop...
### Backing up Data Drive...
Access denied
Unable to create directory - J:\Media Centre Backup\Data Drive\System Volume Inf
ormation
Invalid number of parameters
****** System Backup Complete! ******
Press any key to continue . . .
 
Looks like it's failing to copy over the System Volume Information dir, which you won't need. Try using the /s switch instead of /e maybe unless there are any empty dirs you really need to be copied over.
 
Still no luck coding now looks like this with the same error message:

@Echo off
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y

echo ****** Complete System Backup ******

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up Data Drive...
%backupcmd% "E:" "%drive%\Data Drive"

xcopy /Q /Y /S /I e:\* c:\Backup E Drive

echo ****** System Backup Complete! ******
@pause
 
ace2109 said:
Still no luck coding now looks like this with the same error message:

@echo off
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y

echo ****** Complete System Backup ******

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up Data Drive...
%backupcmd% "E:" "%drive%\Data Drive"

xcopy /Q /Y /S /I e:\* c:\Backup E Drive

echo ****** System Backup Complete! ******
@pause

Won't it have to be xcopy /Q /Y /S /I e:\* "J:\data drive" instead?
 
Sorted guys:

Originally Posted by ace2109
Still no luck coding now looks like this with the same error message:

@Echo off
set drive=J:\Media Centre Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /t /e /h /i /r /y

echo ****** Complete System Backup ******

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

echo ### Backing up Data Drive...
%backupcmd% "E:" "%drive%\Data Drive"

xcopy /Q /Y /S /I e:\* c:\Backup E Drive

echo ****** System Backup Complete! ******
@pause

just had to delete this part of the code

echo ### Backing up Data Drive...
%backupcmd% "E:" "%drive%\Data Drive"

and it worked fine
 
Back
Top Bottom