+ Post New Thread
Results 1 to 13 of 13
Windows 7 Thread, Batch File for Backup in Technical; I am using the below mentioned backup script inorder to backup folders to a drive on the network. I can't ...
  1. #1

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Batch File for Backup

    I am using the below mentioned backup script inorder to backup folders to a drive on the network. I can't set the permissions for a particular user, i want to give full control to the Domain Admin & this particular user which is performing this bakup. I don't want any other acounts to show up when the backup is completed and i go to the remote computer "sbptfs" to see the only these two accounts under the folders properties (security) tab. I have alos tried to use the :r switch but idoesn't work and no permissions are modified at the destination machine.

    I have been working for the last 2 days and read differet articles, but no luck

    Any propmt response will be really appreciated. i need immediate help.
    thanks,

    Mike.



    @echo OFF
    net use z: \\sbptfs\share$

    for /f "tokens=2*" %%a in ('net user "%Username%" /domain ^| find /i "Full Name"') do set DisplayName=%%b
    ECHO .....................Backing up %DisplayName%


    :: variables
    set drive=z:\%DisplayName%
    set backupcmd=xcopy /s /c /d /e /h /i /r /y
    icacls * /T /C /Grant %Username%:F
    icacls * /T /C /Grant "Domain Admins":F

    ECHO .....................Backing up Desktop...
    %backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop"

    ECHO .....................Backing up Favorites...
    %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

    ECHO .....................Backing up Documents...
    %backupcmd% "%USERPROFILE%\Documents" "%drive%\Documents"


    net use z: /delete

    pause

  2. #2

    Join Date
    May 2009
    Location
    Surrey
    Posts
    15
    Thank Post
    3
    Thanked 1 Time in 1 Post
    Rep Power
    0

    A step closer

    Just a few changes that may help you to work out the problem

    Code:
    @echo OFF
    REM VERIFY ON
    
    :: variables
    set DisplayName=
    set drive=
    set backupcmd=xcopy /s /c /d /h /i /r /y /O /X
    
    net use z: \\sbptfs\share$
    
    for /f "tokens=3* delims= " %%g in ('net user "%Username%" /domain ^| findstr /b /i /C:"Full Name"') do set DisplayName=%%g
    IF [%DisplayName%]==[] echo. Problem with DisplayName [%DisplayName%] && goto :eof
    
    ECHO ...........Backing up "%DisplayName%"
    
    set drive=z:\%DisplayName%
    IF NOT EXIST "%drive%\." echo. Problem with drive [%drive%] && goto :eof
    
    cd /d "%USERPROFILE%"
    for %%g in (Desktop Favorites Documents) do (
        icacls %%g\* /T /C /Grant      %Username%:F     >icacls_%%g.log 2>&1
        icacls %%g\* /T /C /Grant "Domain Admins":F    >>icacls_%%g.log 2>&1
        findstr /C:"Access is denied" icacls.log >nul
        IF %ERRORLEVEL% EQU 0 ECHO.           ** ICACLS warnings occured, view icacls_%%g.log **
    
        ECHO.
        ECHO            ..........Backing up %%g...
        mkdir "%drive%\%%g" 2>NUL
        %backupcmd% "%%g"   "%drive%\%%g"  >xcopy_%%g.log 2>&1
    )
    net use z: /delete
    
    pause
    Creates some log files to look at. (found in %USERPROFILE% folder)

  3. #3

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi,

    I am trying to execute this script but its not executed on my machine windows 7 64-bit. I am confused for a couple of code lines you mentioned.

    :: variables
    set DisplayName=
    set drive=

    I am not sure if we have defined set drive=z:\%displayname%, then wgy are we mentioning again.

    My script works fine it backs up to the target computer "sbptfs" and creates a folder 'share$' and backs all the three folders which i want.

    The only broblem i am facing is the permissions.

    I am using following two lines of codes for the permissions.

    icacls * /T /C /Grant %Username%:F
    icacls * /T /C /Grant "Domain Admins":F

    Which does not define the proper rights.

    I need help to modify only the permission section the rest my script works perfect.

    I would really appreciate if someone can help me modify the permission section.

    Thanks for the script and i look forward to your reply.

    Mike.

  4. #4

    Join Date
    May 2009
    Location
    Surrey
    Posts
    15
    Thank Post
    3
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Hi Mike,

    Any clues as to why it isn't executing? Does it output anything to the log files I mentioned?
    The variables section at the top is just my preference I guess, I like to see what variables I'm using throughout the script.

    I just thought that if we could get some logs created we could see what is/isn't happening with the ICACLS command.
    With your own script, are you in the correct path when you issue ICACLS ?

    You mention that your script creates a folder share$. I thought that you map that folder as the Z drive ???

    Karl

  5. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by Mike12 View Post
    My script works fine it backs up to the target computer "sbptfs" and creates a folder 'share$' and backs all the three folders which i want.

    The only broblem i am facing is the permissions.
    So do you want the permissions of the new files set, or the old files? As currently you're setting the permission of the file that already has the permissions.

    Then copying the file, and thus losing permissions on the copy

    If you want the backup to have the same permissions the original has, you're doing it in the wrong order (Unless I misunderstood what you wanted?)

    Steve

  6. #6


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,629
    Thank Post
    250
    Thanked 2,908 Times in 2,140 Posts
    Rep Power
    829
    Why bother setting the permissions at all? Won't "Domain Admins" and the user already have the relevant rights at the share level?

  7. #7

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi Steve,


    Yes, i loose the permissions when the files or folder are backed up to the target computer.

    Help me out how to have the same permissions once i backup the folders & files from the source machine to the target machine.

    I have tried but can't fix the code for the permission only.

    Otherwise the code works fine and it backs up (desktop, documents favorites) to 'Spbtfs' which is the target computer on the network.

    Mike.

  8. #8

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    At the target computer when i access the rights the user who performed the backup doesn't have the proper rights all boxes are greyed out.
    The user name is not present with the domain admins.
    There are only Users (SBPTFS\Users).
    There is no account with my name.

  9. #9

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by Mike12 View Post
    At the target computer when i access the rights the user who performed the backup doesn't have the proper rights all boxes are greyed out.
    The user name is not present with the domain admins.
    There are only Users (SBPTFS\Users).
    There is no account with my name.
    Easiest way that "should" work for you.

    Is changing this:
    Code:
    set backupcmd=xcopy /s /c /d /e /h /i /r /y
    to:

    Code:
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /O /X /E /H /K
    OXEHK = Copies ownership/ACL, Copies audit settings, copies attributes, copies hidden/sysfiles, and copies folder/subfolders.

    (Note, inherited settings are never copied. Got to be direct set)

    Steve

  10. #10

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by Steve21 View Post
    Easiest way that "should" work for you.

    Is changing this:
    Code:
    set backupcmd=xcopy /s /c /d /e /h /i /r /y
    to:

    Code:
    set backupcmd=xcopy /s /c /d /e /h /i /r /y /O /X /E /H /K
    OXEHK = Copies ownership/ACL, Copies audit settings, copies attributes, copies hidden/sysfiles, and copies folder/subfolders.

    (Note, inherited settings are never copied. Got to be direct set)

    Steve

    I updated the code with this line, but now the contents of the folder are not copied to the destination machine.

    Also, permissions are the same, no change.

    If you can help me in writing a simple code for a batch file which i can use on windows 7 inordr to backup my files and folders to a drive on the network.

    My code i don't understand it does everthing except does not update the permissions.

    I have been working on this for the last 4 days, now its driving me crazy.

    Thanks,

    Mike
    Last edited by Mike12; 28th June 2011 at 10:26 PM.

  11. #11

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Thing is without more information could be many things...

    Example, you can't copy ntfs permissions to fat.

    Anything extra you could explain will help

    Steve

  12. #12

    Join Date
    Jun 2011
    Location
    Detroit
    Posts
    6
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by Steve21 View Post
    Thing is without more information could be many things...

    Example, you can't copy ntfs permissions to fat.

    Anything extra you could explain will help

    Steve
    Hi steve,

    I am not copying NTFS permissions to FAT.

    The machine on which the batch file is executed is windows 7 64-bit OS.

    The machine to which the backup files & folders are copied which is "Sbptfs" is a Windows server 2008. Both machines are on the network.

    To windows 7 i login with my credentials and i also have the rights as an domain administrator as well. I run the backup script on windows 7 machine loged in as myself inorder to copy my desktop, documents & favorites to the destination machine "sbptfs".

    The script i am using copies all the three folders with contents to the destination machine and it also pulls my name and creates a folder with my name on the destination machine and put all the three folders inside it. Here when i right cilck on any of the three folder or the parent folder with my name and go to properties and then security tab there are 4 accounts, but there is no account with my name.

    I want to see my account and the domain admin account here only and not other accounts which i mentioned earlier "Users (SBPTFS\Users). There should be an account with my name instead of Users.

    Also the Domain Admin accout should also be there.

    Any help would be highly appreciated.

    Mike.

  13. #13

    Join Date
    May 2009
    Location
    Surrey
    Posts
    15
    Thank Post
    3
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Mike,

    Please post back the output from

    icacls %USERPROFILE%\Desktop

    icacls Z:\<Name>\Desktop

    Also, if you could do the same for a sample file, just to help us see the exact permissions for a folder and file.

    Karl



SHARE:
+ Post New Thread

Similar Threads

  1. Help with beginner script/batch file to rename Program File?
    By El_Nombre in forum How do you do....it?
    Replies: 3
    Last Post: 23rd June 2011, 03:05 PM
  2. Batch file needed please
    By cromertech in forum Scripts
    Replies: 2
    Last Post: 21st June 2011, 12:50 PM
  3. Replies: 4
    Last Post: 15th July 2010, 05:27 PM
  4. Batch File (select random file) help
    By fil_b in forum Windows Server 2000/2003
    Replies: 5
    Last Post: 5th November 2009, 05:13 AM
  5. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 08:48 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
  •