Auto Backup

March 24, 2010 at 21:21:49
Specs: Windows 7 / XP / Vista
help needed creating a batch file for auto backup on my network.

I repair computers and im trying to build a batch that i can run on the client computers so that i can automatically backup "%users% My Documents, Music, My Pictures and so on. I use a file server to copy and store the data until the PC is repaired then copy them back. mainly i need help with mkdir in my batch that will prompt me for input for a name when auto making me a directory on a mapped network drive that is set with pushd at the start of the batch file. I want to backup all users in the documents and settings folder to make sure i get all the users information like music contacts my pictures ect.


CODE/

CLS

pushd \\server\backup\


MKDIR ??? USER INPUT NEEDED HERE FOR Custmer name in backup folder

xcopy /e /v /y c:\Documents and Settings\%ALL Users%\My Music\ Z:\USER INPUT FROM MKDIR\ALL USERS\My Music

xcopy /e /v /y c:\Documents and Settings\%ALL Users%\My Pictures\ Z:\USER INPUT FROM MKDIR\ALL USERS\My Pictures

popd \\server\backup\

exit

CODE\



See More: Auto Backup

Report •

#1
March 24, 2010 at 21:46:41
set /p dest=enter the destination directoryname (customer):
cd /d z:\work
mkdir %dest%
...
::-------
something like that?

Report •

#2
March 24, 2010 at 22:06:20
yes that did it nicely. now i need xcopy destination to be whatever the input was from that prompt so it will know what folder to xcopy to.

also maybe the command to backup all users in the users directory

say like

XCOPY

/Documents and Settings\mary\My Pictures
/Documents and Settings\frank\My Pictures
/Documents and Settings\unknown user\My Pictures

and it MK DIR of the user folders as they were on the client computer.

that way when i look in the folder created by batch i see

mary\My Pictures
frank\My Pictures
unknown user\My Pictures


Report •

#3
March 25, 2010 at 02:37:44
You don't need to navigate to any directory, to use MKDIR, you can just use the path in the MKDIR command itself. Do not use navigation (CD, PUSHD, POPD) unless you need it, and in this case, you don't.

Also have a detailed look at XCOPY, and check which other params you may need (special files, ...)


Report •

Related Solutions

#4
March 25, 2010 at 06:30:43
so after MKDIR creates the folder it automatically switches to that dir? what do i put in for destination on xcopy. i didn't quiet understand that.

Report •

#5
March 25, 2010 at 06:47:55
Just enter the paths in the parameters of XCOPY and MKDIR and forget about navigation, that is what it means.

How's your script ? Did Nbranes hint work ?


Report •

#6
March 25, 2010 at 07:13:30
yes Nbranes code worked for that part. now im just stuck on xcopy. here is my code so far. i use pushd to mount a network drive to the local machine and popd to unmount it. not really nav. commands i dont think.

how do i make xcopy get all the users in the users directory if i dont know the name of every user? %ALL USERS%?


CODE

CLS

pushd \\server\backup\


set /p dest=enter the destination directory name (customer):
cd /d z:\work
mkdir %dest%

xcopy /e /v /y c:\users\%ALL Users%\My Music\ Z:\%dest%

xcopy /e /v /y c:\uaers\%ALL Users%\My Pictures\ Z:\%dest%


popd \\server\backup\

exit

END CODE


Report •

#7
March 25, 2010 at 19:47:13
can't you just go to the \documents and settings on the customer's computer and xcopy /s everything back to z?

set /p dest=enter the destination directoryname (customer):
cd /d z:\work
mkdir %dest%
cd /d "c:\documents and settings"
xcopy /s *.* z:\work\%dest%

like Tvc said, you prob'ly don't need to navigate back, but
i'm not good with xcopy, so i usually do it that way so that i can have more confidence that the result is what i intended.
this might also work (running from z:\work\%dest%
xcopy /s "c:\documents and settings" *.* .\


Report •

#8
March 25, 2010 at 19:58:26
cool ill haft to give that a try. i was looking at xcopy under vista and it says its been depleted or something and to use robocopy. so ill have to change some things to use it with vista and 7. xp isn't so UAC controlled so commands run a whole lot smoother from batch.

Report •

#9
March 25, 2010 at 21:35:07
after a while of playing around i got it working under xp, vista, and windows 7 here is the code for each in case anybody else is interested. Thanks for helping me out there guys. Maybe this will help someone else.

VISTA & WIN 7

CODE/

CLS

pushd \\server\backup drive\

@echo off
TITLE Vista File Copy

ECHO.
ECHO Lets Clone These Files!

set /p dest=Enter The Backup Folder Customer Name:
cd z:\
mkdir %dest%
cd "c:\users"
xcopy /S /E /W /V c:\users\*.* z:\%dest%

popd \\warehouse\backup\

CODE/

XP CODE/

CLS

pushd \\server\backup\

@echo off
TITLE XP FILE COPY

ECHO.
ECHO Lets Clone These Files!

set /p dest=Enter The Backup Folder Customer Name:
cd Z:\
mkdir %dest%
cd /d "c:\Documents and Settings\"
xcopy /E /S /V /W *.* z:\%dest%

popd \\server\backup\


CODE/


Report •

#10
March 26, 2010 at 04:37:37
That's OK, I see only 1 bug (well, it is morning here, so) :
When you enter a value WITH whitespaces for variable DEST, whole of your script will fail:

D:\Temp>type test.cmd
@echo on

set /p dest=Enter The Backup Folder Customer Name:
mkdir %dest%

D:\Temp>test.cmd

D:\Temp>set /p dest=Enter The Backup Folder Customer Name:
Enter The Backup Folder Customer Name: My name is Jeff

D:\Temp>mkdir My name is Jeff

D:\Temp>dir
Volume in drive D is Program and Data
Volume Serial Number is C8BE-1EC5

Directory of D:\Temp

26/03/2010 12:38 <DIR> .
26/03/2010 12:38 <DIR> ..
26/03/2010 12:38 <DIR> is
26/03/2010 12:38 <DIR> Jeff
26/03/2010 12:38 <DIR> My
26/03/2010 12:38 <DIR> name
26/03/2010 12:37 79 test.cmd
1 File(s) 79 bytes
6 Dir(s) 21.310.701.568 bytes free

D:\Temp>


Report •

#11
March 26, 2010 at 04:44:06
Bug 2 would be the architectual error in that you can easily write this script as one. I see that only the source directory of XCOPY command is different ?

So, if you can determine (from the batch) if your system is XP, 7 or Vista, you could easily have 1 script to auto-detect. What does this say on 7 or Vista

D:\Temp>echo %OS%
Windows_NT

D:\Temp>

It would be fun it this bug would still be there in 7


Report •

#12
March 26, 2010 at 07:27:42
i noticed the white space problem myself but its no big deal to just input with no spaces.

yeah it would be nice to auto detect. well in vista it still spits out
Windows_NT for the os version. im not around my server right now to test it on 7 in vmware but i will and post the results to that. but yeah a few things change from xp to vista. mainly in the xcopy command. if u cd /d to C:users in vista then add the C:users to the xcopy command it still runs, but in xp u cant use the path to the directory your already in. I had to just use a wild card to get it going instead of using the full path. i did test the vista script in 7 and it ran no problem. didn't even haft to elevate to administrator. it just ran straight out of the gate. witch was surprising because the root directory and system files always prompt u for UAC before u even copy to those directory's. "shrugs" weird..


Report •

#13
March 26, 2010 at 07:48:55
Part of it may be explained by this:

Always use the /D parameter with the CD command !

Otherwise, you get this kind of buggy behaviour:

C:\Documents and Settings>cd "d:\temp"

C:\Documents and Settings>dir "d:\temp"
Volume in drive D is Program and Data
Volume Serial Number is C8BE-1EC5

Directory of d:\temp

26/03/2010 15:42 <DIR> .
26/03/2010 15:42 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 21.314.338.816 bytes free

C:\Documents and Settings>


The CD command is totally ignored, since by coincidence, the active drive was not the same as the targetted drive. As the DIR command shows, the directory exists all right.


Report •

#14
March 26, 2010 at 07:53:33
good eye good eye.

Report •

#15
March 26, 2010 at 10:14:06
I guess that all changes between XP and 7, which relate to THIS thread, is that Robocopy is included in 7, while it is "optional" in XP

The rest is the same ... I guess. If you want to know, just run the command's usage on each version:

XCOPY /?
CD /?

And look for differences. If there is a behavioural difference, and it is not documented, but it is essential, it may be a bug


Report •

Ask Question