Copia di una cartella mantenendo i permessi NTFS
Talvolta può capitare di avere la necessità di creare una copia di una cartella con le relative impostazioni di sicurezza a causa di una risistemazione di un file server per esempio.
Per eseguire tale attività è possibile utilizzare vari approcci uno dei quali è utilizzare Robocopy (Robust File Copy) il tool a riga di comando presente già in Windows NT 4.0 all’interno del Windows Resource Kit e inserito poi come comando nativo in Windows Vista/Windows Server 2008 e successivi.
Per eseguire ad esempio la copia della cartella PrivateDocs in un percorso diver locale o remoto è possibile utilizzare il seguente comando:
robocopy “SourcePath\PrivateDoc” “DestinationPath\PrivateDoc” /MIR /SEC /SECFIX /R:1 /W:1 /V /TEE /LOG:Copy-PrivateDocs.log
Dove i parametri hanno il seguente significato:
/MIR
Mirrors a directory tree (equivalent to /e plus /purge)
The /mir option is equivalent to the /e plus /purge options with one small difference in behavior:
- With the /e plus /purge options, if the destination directory exists, the destination directory security settings are not overwritten.
- With the /mir option, if the destination directory exists, the destination directory security settings are overwritten.
/SEC
Copies files with security (equivalent to /copy:DAT)
/SECFIX
Fixes file security on all files, even skipped ones
/R
Specifies the number of retries on failed copies. The default value of N is 1,000,000 (one million retries)
/W
Specifies the wait time between retries, in seconds. The default value of N is 30 (wait time 30 seconds)
/V
Produces verbose output, and shows all skipped files
/TEE
Writes the status output to the console window, as well as to the log file
/LOG
Writes the status output to the log file (appends the output to the existing log file).
Il comando può essere anche eseguito più volte consentendo così di eseguire test o di gestire modifiche alla struttura di un file server con downtime minimi in quanto è possibile eseguire la copia dei file non modificati a ridosso dello spostamento preventivamente.
Per quanto riguarda la gestione dei permessi NTFS con RoboCopy si veda il seguente post
Robocopy /MIR switch – mirroring file permissions
> ROBOCOPY <source> <target> /MIR /SEC /SECFIX
/MIR will replicate data and security (as /SEC is specified) for changed files, and /SECFIX will update just the security for unchanged files. Add /V to the command line if you want to see which files are having their security “fixed” without having their data copied.
Robocopy è ottimo tool per la copia di directory in percorsi diversi estremamente duttile con buone performance e quindi utile in vari scenari, a riguardo si vedano ad esempio:
- Use Robocopy to Preseed Files for DFS Replication
- 20 Helpful Steps Migrating Windows Server 2003 to 2012 R2
Se però si ha la necessità di implementare una replica per sincronizzare dei file risulta decisamente più performante la funzionalità Storage Replica che sarà introdotta in Windows Server 2016, a riguardo si vedano le comparazioni riportare nel post Storage Replica versus Robocopy: Fight!.
Se invece la necessità è quella di migrare un file server è possibile ricorrere ai Windows Server Migration Tools a riguardo si vedano i seguenti:
- Migrate File and Storage Services to Windows Server 2012 R2
- Step-By-Step: Migrating a Windows Server 2003 file server, NTFS and Share Rights to Windows Server 2012 R2
- Migrate File Server Using The File Server Migration Toolkit Within Server 2012 R2
- KB2873617 You cannot use the Smigdeploy.exe tool in Windows Storage Server 2012 or Windows Storage Server 2008 R2
Volendo per la migrazione di un file server WS2003/WS2008 è anche possibile utilizzare il
Microsoft File Server Migration Toolkit 1.2, a riguardo si veda Step-By-Step: Migrating a 2003 file server with Microsoft File Server Migration Toolkit.