+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, Email System Backup using FOR, Reg Query, FindStr, Robocopy-Need help! in Coding and Web Development; I am trying to write a batch file to backup users emails. We have a mix of Express and Outlook ...
  1. #1
    wiggum123's Avatar
    Join Date
    May 2010
    Location
    Bristol
    Posts
    58
    Thank Post
    13
    Thanked 2 Times in 2 Posts
    Rep Power
    8

    Email System Backup using FOR, Reg Query, FindStr, Robocopy-Need help!

    I am trying to write a batch file to backup users emails. We have a mix of Express and Outlook 2007 users. Most of which have changed their data store folders.
    I have written a batch file that checks if Outlook 2007 and Express are installed, searches the registry for the location of their personal folders and robocopies them to a folder on their home drive (H:\).
    Robocopy is set to a variable at the top of the file to account for some machines not having it installed.
    Code:
    set RoboCopy=\\beaufort.local\NETLOGON\robocopy.exe
    I have never used the FOR F/ loop, or REG QUERY or FINDSTR so I have been walking blind for the past few days.
    The first question I have is;
    With Outlook 2007, there are 2 registry entries for the File Store location, When using the FOR /F loop, how can I assign each key it finds to a different variable.
    I have this so far;
    Code:
    FOR /F "TOKENS=1* DELIMS=<tab><space>" %%G IN ('REG.exe QUERY "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Catalog" ^|findstr /v /C:"HKEY"') DO (
    %RoboCopy% "%%G" "h:\%username%'s Outlook Backup" "*.pst" /E /ZB /R:5 /W:1 /PURGE)
    This does nothing at the moment.
    Also, when I call the %%G string it seems to add the location of the batch file before the string, this is from the Source : section of the robocopy it runs
    Code:
    Source : C:\Documents and Settings\Administrator.BEAUFORT\Desktop\    C:\Outlook\backup.pst\
    There are also 3 spaces before the path in the registry file, is there a way of removing this?

    I hope this makes some sense...


    Here is a copy of the entire script, I have added in loads of pauses to see where it fails;
    Code:
    TITLE Backup %username%'s Outlook Files
    cls
    COLOR 1F
    
    set RoboCopy=\\beaufort.local\NETLOGON\robocopy.exe
    md "H:\%username%'s Outlook Backup"
    
    TITLE Checking for Outlook 2007
    pause
    IF EXIST "C:\Documents and Settings\%USERNAME%.Beaufort\Local Settings\Application Data\Microsoft\Outlook\*.*" (echo This user is using Office Outlook, backing up Outlook folder
    pause
    GOTO OUTLOOK)
    echo User not using Outlook 2007
    IF ERRORLEVEL=1 (GOTO ERROR)
    pause
    cls
    GOTO EXPRESS
    
    :OUTLOOK
    TITLE  Backing up %username%'s Outlook 2007 Files
    ECHO Backing up files, This may take some time
    FOR /F "TOKENS=1* DELIMS=    " %%G IN ('REG.exe QUERY "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Catalog" ^|findstr /v /C:"HKEY"') DO (
    %RoboCopy% "%%G" "h:\%username%'s Outlook Backup" "*.pst" /E /ZB /R:5 /W:1 /PURGE)
    pause
    GOTO EXPRESS
    
    :EXPRESS
    TITLE Checking for Outlook Express
    IF EXIST "C:\Documents and Settings\%USERNAME%\Application Data\Identities\" (echo This user is using Outlook Express, backing up Outlook Express folder
    pause
    IF ERRORLEVEL=1 (GOTO ERROR)
    GOTO EXPRESSBACKUP)
    echo User not using Outlook Express
    pause
    IF ERRORLEVEL=1 (GOTO ERROR)
    cls
    GOTO FINISH
    
    :EXPRESSBACKUP
    TITLE Backing up %username%'s Outlook Express Files
    md "H:\%username%'s Outlook Backup\Outlook Express"
    md "H:\%username%'s Outlook Backup\Outlook Express Addressbook"
    for /f "tokens=5" %%i in ('reg.exe query HKCU\Identities\ ^|findstr /C:"Default User ID"') do SET ID=%%i
    for /f "tokens=4" %%g in ('reg.exe query "HKEY_CURRENT_USER\Identities\%ID%\Software\Microsoft\Outlook Express\5.0\" ^|findstr /C:"    Store Root"') do (
    %RoboCopy% "%%g" "h:\%username%'s Outlook Backup\Outlook Express" "*.dbx" /E /ZB /R:5 /W:1 /PURGE)
    pause
    %RoboCopy% "C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Address Book" "h:\%username%'s Outlook Backup\Outlook Express Addressbook" /E /ZB /R:5 /W:1 /PURGE
    pause
    cls
    IF ERRORLEVEL=1 (GOTO ERROR)
    GOTO FINISH
    
    :FINISH
    COLOR 2F
    CLS
    TITLE Backed up %username%'s Outlook Files
    echo %USERNAME%'s Outlook Backed Up
    pause
    EXIT
    
    :ERROR
    CLS
    COLOR 4E
    ECHO %USERNAME% Error during Backup
    EXIT

  2. #2
    wiggum123's Avatar
    Join Date
    May 2010
    Location
    Bristol
    Posts
    58
    Thank Post
    13
    Thanked 2 Times in 2 Posts
    Rep Power
    8
    Hey
    Thanks for the reply. Ill try using the n+, I had seen this before but it looked a bit complicated. Makes more sense now someone explains it
    If not I'll have to dust off my VB knowledge!

  3. #3
    wiggum123's Avatar
    Join Date
    May 2010
    Location
    Bristol
    Posts
    58
    Thank Post
    13
    Thanked 2 Times in 2 Posts
    Rep Power
    8
    Cool, That seems to work percectly.
    Next problem is...
    I need to remove from the %RegKey!N!% whatever is afer the final \
    For example, one of the strings is pulls out is ; C:\Outlook\pudsey.pst
    If you present this to robocopy is sets the source as C:\Outlook\pudsey.pst\
    which obviously doesnt exist, is there a way of shortening this to display C:\Outlook\
    These files arent all in the same place, or called the same thing, so it needs to be specificaly vague...
    Also... there are 3 spaces at the beginning of the string. I can remove these by changing the DELIMS=<tab> to DELIMS=<TAB><SPACE> but one of the strings is in the documents and settings folder and it thinks that the space in that is a delimiter and shortens it to; C:\Documents, fairly useless.... any ideas?

SHARE:
+ Post New Thread

Similar Threads

  1. Script Help - Query AD and add it to a reg key
    By Stuart_C in forum Scripts
    Replies: 6
    Last Post: 14th May 2010, 06:04 PM
  2. ROBOCOPY Through NT Backup Utility
    By Agarwal_Ashu in forum Windows Server 2000/2003
    Replies: 1
    Last Post: 16th March 2010, 11:18 AM
  3. VBS to Backup Folder and then Restore from Reg
    By simons2009 in forum Scripts
    Replies: 22
    Last Post: 2nd June 2009, 07:11 AM
  4. Backup Script for NT backup and Robocopy
    By ChrisH in forum Scripts
    Replies: 12
    Last Post: 20th October 2005, 01:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •