Mike12 Posted June 27, 2011 Posted June 27, 2011 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
mrwoberts Posted June 27, 2011 Posted June 27, 2011 Just a few changes that may help you to work out the problem @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)
Mike12 Posted June 28, 2011 Author Posted June 28, 2011 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.
mrwoberts Posted June 28, 2011 Posted June 28, 2011 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
Steve21 Posted June 28, 2011 Posted June 28, 2011 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
Arthur Posted June 28, 2011 Posted June 28, 2011 Why bother setting the permissions at all? Won't "Domain Admins" and the user already have the relevant rights at the share level?
Mike12 Posted June 28, 2011 Author Posted June 28, 2011 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.
Mike12 Posted June 28, 2011 Author Posted June 28, 2011 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.
Steve21 Posted June 28, 2011 Posted June 28, 2011 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: set backupcmd=xcopy /s /c /d /e /h /i /r /y to: 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
Mike12 Posted June 28, 2011 Author Posted June 28, 2011 (edited) Easiest way that "should" work for you. Is changing this: set backupcmd=xcopy /s /c /d /e /h /i /r /y to: 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 Edited June 28, 2011 by Mike12
Steve21 Posted June 28, 2011 Posted June 28, 2011 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
Mike12 Posted June 29, 2011 Author Posted June 29, 2011 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.
mrwoberts Posted June 30, 2011 Posted June 30, 2011 Mike, Please post back the output from icacls %USERPROFILE%\Desktop icacls Z:\\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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now