Need help with creating a script to backup to a USB hard drive.

10 replies [Last post]
paulyballs
paulyballs's picture
Offline
Joined: 23.01.2009

Hi everyone,

I'm hoping someone can help me here. Here is my scenario.

 

Backup all data in C:\Documents and Settings\Username\

Destination: External USB Hard Disk G:\Backup\

I want the backup to be incremental and be able to backup up PST files while Outlook is open.  Can someone help me with a script to create a batch file?  I've tried everything and it's not working properly.

Thanks so much,

Paul

quatermass
quatermass's picture
Offline
Joined: 01.05.2008
Copying open files on Windows

It's pretty easy to create a cwrsync script. Not so easy to do this and copy all files in the user folder due to Windows keeping open lots of files. Happily there is a solution. Microsoft has released several free utilities to allow any command line program to copy open files. I've made such a script using these utils and you can view this script which I use regularly to backup using xcopy or rsync the user profile folder 100% intact. http://mytriops.com/misc/save_profile/ Everything is provided. Any questions, just ask.

paulyballs
Offline
Joined: 23.01.2009
Thanks for the info. I just

Thanks for the info. I just have one problem after I run the script. I used the Rsync one to copy to an external drive. I get this error after I run run.bat

The application failed to start because cygiconv-2.dll was not found. Re-installign the application may fix the problem. Any ideas?

Here is what my vss-exec looks like:

call "%~dp0\vss-setvar.cmd"
@ECHO OFF

REM THis line is for setting a dummy drive.
REM If you have a B: drive. Then change this to one you don't have!
SET driveletter=Z

SET user=%USERNAME%

REM Rsync line
set cygwin=notnsec
REM Rsync line
SET RSYNC_PASSWORD=smith?

REM Don't change this line
dosdev %driveletter%: %SHADOW_DEVICE_1%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
REM ----------------------------------------------------------------------

REM ECHO Copying files back to remote computer, please wait...
REM rsync -rcDPtph --modify-window=3 --progress --delete-after -i --log-file=saveprofile.log --delete-excluded --exclude=Temp/ "/cygdrive/%driveletter%/documents and settings/%user%/" fred@remoteserver::profile/%user%/

REM Uses the standard xcopy command. Remember your true source drive is set in the RUN.BAT
REM and variable 'driveletter' is set to the VSS shadow drive.
REM ECHO Copying profile of the person using this script to spare drive
REM set source=%driveletter%%USERPROFILE:~1%
REM XCOPY "%source%\*.*" D:\backup_profile\ /E/C/I/H/R/Y

REM or use Rsync to do this.
rsync -rqcDPtph --modify-window=3 --progress --delete-after -i --log-file=saveprofile.log --delete-excluded --exclude=Temp/ "/cygdrive/%driveletter%/documents and settings/%user%/" /cygdrive/G/backup_profile/%user%/

IF %ERRORLEVEL% GTR 0 goto error
ECHO.
ECHO.
ECHO Finished. No error detected.
ECHO.
ECHO.
:return
REM ----------------------------------------------------------------------

ECHO Removing temporary driveletter %driveletter%:
ECHO.

dosdev -r -d %driveletter%:

EXIT

:error
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO =============================================
ECHO ERROR FOUND IN COPYING PROFILE.
ECHO.
goto return

paulyballs
Offline
Joined: 23.01.2009
FYI Here is the output from

FYI

Here is the output from cmd:

---------- C:\DOCUME~1\PANUSP\LOCALS~1\TEMP\OSVERSION.TMP
Microsoft Windows XP [Version 5.1.2600]

---------- C:\DOCUME~1\PANUSP\LOCALS~1\TEMP\OSVERSION.TMP

About to run using vshadow_XP.exe

VSHADOW.EXE 2.2 - Volume Shadow Copy sample client
Copyright (C) 2005 Microsoft Corporation. All rights reserved.

(Option: Generate SETVAR script 'vss-setvar.cmd')
(Option: Execute binary/script after shadow creation 'vss-exec.cmd')
(Option: Create shadow copy set)
(Gathering writer metadata...)
(Waiting for the asynchronous operation to finish...)
Initialize writer metadata ...
Discover directly excluded components ...
- Excluding writer 'MSDEWriter' since it has no selected components for restore.

Discover components that reside outside the shadow set ...
Discover all excluded components ...
Discover excluded writers ...
Discover explicitly included components ...
Verifying explicitly specified writers/components ...
Select explicitly included components ...
* Writer 'Microsoft Writer (Service State)':
- Add component \Content Indexing Service
- Add component \Config Directory
- Add component \Event Logs
* Writer 'Microsoft Writer (Bootable State)':
- Add component \COM+ Registration Database
- Add component \Registry
* Writer 'WMI Writer':
- Add component \WMI
Creating shadow set {a0d77462-f62e-43a4-9f79-1fe6b1889d9f} ...
- Adding volume \\?\Volume{24967541-cb08-11dd-953e-806d6172696f}\ [C:\] to the s
hadow set...
Preparing for backup ...
(Waiting for the asynchronous operation to finish...)
(Waiting for the asynchronous operation to finish...)
Creating the shadow (DoSnapshotSet) ...
(Waiting for the asynchronous operation to finish...)
(Waiting for the asynchronous operation to finish...)
Shadow copy set succesfully created.

List of created shadow copies:

Querying all shadow copies with the SnapshotSetID {a0d77462-f62e-43a4-9f79-1fe6b
1889d9f} ...

* SNAPSHOT ID = {264c73c6-66af-4dd1-aaa9-47cbb8908d21} ...
- Shadow copy Set: {a0d77462-f62e-43a4-9f79-1fe6b1889d9f}
- Original count of shadow copies = 1
- Original Volume name: \\?\Volume{24967541-cb08-11dd-953e-806d6172696f}\ [C:
\]
- Creation Time: 1/26/2009 9:17:02 AM
- Shadow copy device name: \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
- Originating machine: (null)
- Service machine: (null)
- Not Exposed
- Provider id: {b5946137-7b9f-4925-af80-51abd60b20d5}
- Attributes: Auto_Release

Generating the SETVAR script (vss-setvar.cmd) ...
- Executing command 'vss-exec.cmd' ...
-----------------------------------------------------

C:\>call "C:\\vss-setvar.cmd"

[This script is generated by VSHADOW.EXE for the shadow set {a0d77462-f62e-43a4-
9f79-1fe6b1889d9f}]

C:\>SET SHADOW_SET_ID={a0d77462-f62e-43a4-9f79-1fe6b1889d9f}

C:\>SET SHADOW_ID_1={264c73c6-66af-4dd1-aaa9-47cbb8908d21}

C:\>SET SHADOW_DEVICE_1=\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
Current definition: Z: = \??\GLOBALROOT\Device\HarddiskVolumeShadowCopy1

paulyballs
Offline
Joined: 23.01.2009
OK so I was able to get it

OK so I was able to get it started but now I get an error during the copy. Here is the log.

I made G: the external drive.

*************...........
rsync: readlink "/cygdrive/Z/documents and settings/panusp/Local Settings/Tempor
ary Internet Files/Content.IE5/YIGO519Q/YMPQCAR2PRBXCA3F325XCAI2RAPBCAPLJFEWCAAE
HTBRCAV1UR9ZCA3L12J6CAZJ1W71CAZPUABLCASSVNWYCAPNDXDVCA3FIVY6CAAF4O4ACAZ44I3WCAVK
DMKTCATQRF1HCAJ5OGURCAV18TB9CAS2PDPP.txt" failed: File name too long (91)
rsync: mkdir "/cygdrive/G/backup_profile/panusp" failed: No such file or directo
ry (2)
rsync error: error in file IO (code 11) at main.c(576) [receiver=3.0.3]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(644) [sender=
3.0.3]

=============================================
ERROR FOUND IN COPYING PROFILE.

Removing temporary driveletter Z:

Current definition: Z: = \??\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
Z: deleted.
-----------------------------------------------------
- Mark all writers as succesfully backed up...
Completing the backup (BackupComplete) ...
(Waiting for the asynchronous operation to finish...)
(Waiting for the asynchronous operation to finish...)

Snapshot creation done.

0
Press any key to continue . . .

paulyballs
Offline
Joined: 23.01.2009
OK I think I got it to work,

OK I think I got it to work, but now when I go into the backup_profile folder on my external drive and I try to get into my folder %username% it says that access is denied. Thoughts?

Sorry for so many questions.

paulyballs
Offline
Joined: 23.01.2009
OK I got everything to work

OK I got everything to work the way I wanted. Questions...is there I way I can make Rsync ALWAYS skip the IE temp int file directory? I get too long filename errors and its unnecessary for me to back these up. Because they are never backed up, rsync goes through them everytime. I would like to omit that directory so the backup runs faster.

Thanks,

quatermass
Offline
Joined: 01.05.2008
Sure you can get rsync to

Sure you can get rsync to reject files or directories.

See Rsync --help

--exclude=PATTERN exclude files matching PATTERN

There is more to using this switch on the many rsync example web sites.

See
http://articles.slicehost.com/2007/10/10/rsync-exclude-files-and-folders

That took me 30secs to find BTW....

quatermass
Offline
Joined: 01.05.2008
Rsync runs on top of cygwin.

Rsync runs on top of cygwin. At present cygwin has a serious filename length problem.

itefix has a version of cygwin I believe that gets over this.

quatermass
Offline
Joined: 01.05.2008
oops. Sorry about that. I

oops. Sorry about that. I guess I forgot to include this vital cygwin dll (cygiconv-2.dll) in my zip file. I'll add it.

quatermass
Offline
Joined: 01.05.2008
Take a look at the security

Take a look at the security permissions on the folder. I bet you'll find their cocked up.
Happens to me too with Rsync and Windows.

I run a Windows command program to reset the owner and permissions afterwards.
Its a known problem with Rsync on Windows.

See http://www.itefix.no/i2/node/11834

fileacl \\ /S "Authenticated Users:F" /S System:F /S Everyone:F /O Everyone /INHERIT /SUB:20 /FILES /FORCE /REMOVEDENY

does it for me.

http://www.gbordier.com/gbtools/fileacl.asp