1.

Solve : Batch - Backingup files when size is under 5 gigs?

Answer»

So the helpdesk I work at is filled with...well lets just SAY not the most competant bunch and backing up files is a pain. I FIGURED creating a batch file will let them just back up with a single push and a few choices so even a monkey could do it.

Problem is that it will be that ever student has a different user name. This will be where my docs will be located ALONG with desktop and the crap needed to backup. So say my user name is smith_john the path would be c:\documents and settings\smith_john, but then we need it to use it for susie and her user name is johnso_susan so her path would be different, it'd be c:\documents and settings\johnso_susan

Is there a way to get the user name so I can put it in the path? Here is what I have....

Code: [Select]CLS

echo Bentley File Copying system created 9/26/2007 by Syoung.
CHOICE /N /C:HydraStudent Are you copying Files to Hydra or back to the student machine? (Hydra, Student)%1
IF CCOPY ==Hydra GOTO Hydra
IF CCOPY ==Student GOTO Student
GOTO END

:Hydra
CHDIR \\Hydra\crc\studata
mkdir USERNAME

CHOICE /N /C:YN Would you like to copy My Documents? (Y,N)%1
IF MYDOC ==Y GOTO MDYES
IF MYDOC ==N GOTO MDNO
GOTO DESKTOP

:MDYES
ECHO Copying My Documents.....
CHDIR \\Hydra\crc\studata\USERNAME
MKDIR My Documents
xcopy "C:\Documents and Settings\USERNAME\My Documents" \\Hydra\crc\studata\USERNAME\My Documents /e /c /k


:MDNO
GOTO DESKTOP


:DESKTOP
CHOICE /N /C:YN Would you like to copy the Desktop folders? (Y,N)%2
IF DESKTOP ==Y GOTO DYES
IF DESKTOP ==N GOTO DNO

:DYes
Echo Copying Desktop files....
CHDIR \\Hydra\crc\studata\USERNAME
MKDIR Desktop
xcopy "C:\Documents and Settings\USERNAME\Desktop" \\Hydra\crc\studata\USERNAME\Desktop /e /c /k

:DNo
GOTO END

:Student
Echo Copying files from Hydra
xcopy \\Hydra\crc\studata\USERNAME\Desktop "C:\Documents and Settings\USERNAME\Desktop" /e /c /k
xcopy \\Hydra\crc\studata\USERNAME\My Documents "C:\Documents and Settings\USERNAME\My Documents" /e /c /k
Echo Copied Files from Hydra to My Documents and Desktop!

:END
Echo Files Copied!
Exit
see the dillema?Would this work?

Edit: changed /set p to set /p Like it is supposed to be.

Code: [Select]CLS

echo Bentley File Copying system created 9/26/2007 by Syoung.

set /P USERNAME=Please Enter the User Name %

CHOICE /N /C:HydraStudent Are you copying Files to Hydra or back to the student machine? (Hydra, Student)%1
IF CCOPY ==Hydra GOTO Hydra
IF CCOPY ==Student GOTO Student
GOTO END

:Hydra
CHDIR \\Hydra\crc\studata
mkdir %USERNAME%

CHOICE /N /C:YN Would you like to copy My Documents? (Y,N)%1
IF MYDOC ==Y GOTO MDYES
IF MYDOC ==N GOTO MDNO
GOTO DESKTOP

:MDYES
ECHO Copying My Documents.....
CHDIR \\Hydra\crc\studata\%USERNAME%
MKDIR My Documents
xcopy "C:\Documents and Settings\%USERNAME%\My Documents" \\Hydra\crc\studata\%USERNAME%\My Documents /e /c /k


:MDNO
GOTO DESKTOP


:DESKTOP
CHOICE /N /C:YN Would you like to copy the Desktop folders? (Y,N)%2
IF DESKTOP ==Y GOTO DYES
IF DESKTOP ==N GOTO DNO

:DYes
Echo Copying Desktop files....
CHDIR \\Hydra\crc\studata\%USERNAME%
MKDIR Desktop
xcopy "C:\Documents and Settings\%USERNAME%\Desktop" \\Hydra\crc\studata\%USERNAME%\Desktop /e /c /k

:DNo
GOTO END

:Student
Echo Copying files from Hydra
xcopy \\Hydra\crc\studata\%USERNAME%\Desktop "C:\Documents and Settings\%USERNAME%\Desktop" /e /c /k
xcopy \\Hydra\crc\studata\%USERNAME%\My Documents "C:\Documents and Settings\%USERNAME%\My Documents" /e /c /k

:END
Echo Files Copying Complete!
ExitWhat are CCOPY, MYDOC and DESKTOP?

NEVERMIND, I figured it out. I just need it to figure out if a directory is under a certain size (5gigs) and to copy if it is. This is the code that worked in case anyone is interested.

Code: [Select]@echo off
:MENU
cls
echo.
echo 1. Backup My Documents
echo 2. Backup Desktop
echo 3. Backup Both
echo 4. Restore backups from Hydra
echo 5. Quit
echo.
set choice=
set /p choice= Enter option ..
echo.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto backMD
if '%choice%'=='2' goto backDT
if '%choice%'=='3' goto backBOTH
if '%choice%'=='4' goto restoreBU
if '%choice%'=='5' goto END
::
echo.
echo.
echo "%choice%" is not a valid option - try again
echo.
pause
goto MENU
::
:backMD
cls
ECHO Backing Up My Documents.....
MD "\\Hydra\crc$\studata\%USERNAME%\My Documents"
xcopy "C:\Documents and Settings\%USERNAME%\My Documents" "\\Hydra\crc$\studata\%USERNAME%\My Documents" /e /c /k
echo PRESS any key ...
pause > nul
goto MENU
::
:backDT
cls
Echo Backing Up Desktop Files....
MD \\Hydra\crc$\studata\%USERNAME%\Desktop
xcopy "C:\Documents and Settings\%USERNAME%\Desktop" \\Hydra\crc$\studata\%USERNAME%\Desktop /e /c /k
echo press any key ...
pause > nul
goto MENU
::
:backBOTH
cls
Echo Backing Up Desktop Files and My Documents....
MD \\Hydra\crc$\studata\%USERNAME%\Desktop
xcopy "C:\Documents and Settings\%USERNAME%\Desktop" \\Hydra\crc$\studata\%USERNAME%\Desktop /e /c /k
xcopy "C:\Documents and Settings\%USERNAME%\My Documents" "\\Hydra\crc$\studata\%USERNAME%\My Documents" /e /c /k
echo press any key ...
pause > nul
::
:restoreBU
cls
echo Restoring Personal Files From Hydra
xcopy \\Hydra\crc$\studata\%USERNAME%\Desktop "C:\Documents and Settings\%USERNAME%\Desktop" /e /c /k
xcopy \\Hydra\crc$\studata\%USERNAME%\My Documents "C:\Documents and Settings\%USERNAME%\My Documents" /e /c /k
echo press any key ...
pause > nul
:End
set choice=
EXIT



Discussion

No Comment Found