Replication of Windows Server 2008 Distribution Points?

donmontalvo
Esteemed Contributor III

Anyone on this list hosting their Distribution Points on Windows Server 2008?

If so, care to share your replication strategy?

Thanks,
Don

--
https://donmontalvo.com
13 REPLIES 13

donmontalvo
Esteemed Contributor III

(bump)

--
https://donmontalvo.com

jarednichols
Honored Contributor

Robocopy as a scheduled task. AD-based account that has read/write over the CasperShare does it. Works a treat.

nkalister
Valued Contributor

what Jared said, except I'll add that you can use local accounts instead of domain accounts if you want to. I'm using local accounts while I await my AD service accounts.

brian_flynn
New Contributor III

How is your environment setup (e.g. Windows everywhere, Mac OS X Master with Windows DP's, etc)?

We were running Mac OS X 10.6.8 JSS and Windows Distribution Points, but I migrated our JSS to a Windows Server 2008 VM. Haven't had any problems at all.

I was using a LaunchDaemon to kick off a bash script which essentially performed rsync's to our Windows Distribution Points when the JSS was on OS X. Now that the JSS is a windows box, I've setup a scheduled task (runs twice a day) to kick off a Powershell script that essentially robocopy's the master share out to all the distribution points then sends me an email with the log file.

Our shares are setup with the same share name everywhere and two AD Domain Local Groups are granted Change/Modify and Read-Only/Read&Execute permissions for the Share and NTFS permissions. The ReadOnly group contains the casper installer account, and the Modify group contains the casper admin and casper replication accounts. We use separate accounts for replication and casper admin to prevent the replication account from accidentally locking out the caper admin account if someone types in the password incorrectly.

The scheduled task on the JSS is setup to run as the casper replication account and the command to run is: "powershell -executionpolicy remotesigned -command D:JSSjssReplication.ps1"

I've attached a copy of the powershell script below. You just need to change the Environment Variables and Email Variables in the beginning of the script to suit your environment.

# Environment Variables
$companyName="Acme Inc"
$logFile="$env:tempjssReplication.Log"
$sourceFolder="D:JSSJSS_DP"
$distributionShare="DP_Share"
$distributionServers = "Server01","Server02","Server03","Server04"

# E-Mail Variables
$Global:emailBody = $null
$smtpServer = "smtp.acme.com"
$emailFrom = "JSS_Repl@acme.com"
$emailTo = "it@acme.com"
$emailSubject = "$env:computername JSS Replication Report"


Function logWrite ([string]$logString) {
  # Write passed string to Log File
  Add-content $logFile -value $logString

  # Write passed string to Email Body
  $Global:emailBody = $Global:emailBody + "$logString`r`n"

}

# Ensure a previous log file does not exist before starting
if(Test-Path -Path $logFile) {
  Remove-Item $logFile
}

# Start by presenting header information
logWrite "$companyName JSS Replication Process..."
logWrite "--------------------------------------------------------------------------------"
$currentTime = Get-Date
logWrite "Started on $currentTime"
logWrite "Hostname: $env:computername"
logWrite "Master Folder: $sourceFolder"
logWrite "Distribution Servers:"
foreach ($server in $distributionServers) {logWrite "`t$server"}
logWrite "User: $env:username"
logWrite "--------------------------------------------------------------------------------"
logWrite "--------------------------------------------------------------------------------"

# Ensure the source Folder exists
if(Test-Path -Path $sourceFolder) {
  # Loop through all Distribution Servers and use robocopy to replicate the Source Folder
  foreach ($server in $distributionServers) {
    $currentTime = Get-Date
    logWrite "Replication to $server started at $currentTime"

    $dpPath = "\$server$distributionShare"
    robocopy $sourceFolder $dpPath /MIR /R:0 /W:0 /COPY:DAT /LOG+:$logFile

    $currentTime = Get-Date
    logWrite "Replication to $server completed at $currentTime"
  }
} else {
  # Source Folder does not exist - Put the error in the email and the log file
  logWrite "ERROR: Source Folder $sourceFolder does not exist!"
}

logWrite "--------------------------------------------------------------------------------"
logWrite "--------------------------------------------------------------------------------"

# Finish with Footer information
$currentTime = Get-Date
logWrite "Completed on $currentTime"
logWrite "--------------------------------------------------------------------------------"

# Send E-Mail with the log file as an attachment
Send-MailMessage -To $emailTo -Subject $emailSubject -From $emailFrom -Body $Global:emailBody -SmtpServer $smtpServer -Attachments $logFile

Kumarasinghe
Valued Contributor

@brian.flynn

Thanks for your script. Really helpful.

Just wanting you to know you might need to change $dpPath command

From;

$dpPath = "$server$distributionShare"

To

$dpPath = "\$server$distributionShare"

PS: It seems like a JAMFnation forum issue as you have to put (3 backslashes) in your post editor to make it

----------------
UPDATE: This blackslash issue has been fixed on 20/03/2013 so disregard this post now.
https://jamfnation.jamfsoftware.com/featureRequest.html?id=799
----------------

brian_flynn
New Contributor III

Thanks for catching it Kumarasinghe. I've updated the script. It is a forum issue, as even going in and editing it it had \ (double backslash) in the script but only displayed (one backslash). You are correct about having to put 3 backslashes in for it to display 2.

jarednichols
Honored Contributor

It's like we're using sed and escaping like crazy...

:)

Kumarasinghe
Valued Contributor

I have edited Brian's script to put status of the robocopy whether it it has errors or not and mention it on the email. So you don't need to check the log file manually to see if there are any errors.

Then put a scheduled task using a PowerShell command

powershell -executionpolicy remotesigned -command D:JSS_DP_Rep_site1.ps1

PowerShell Script (JSS_DP_Rep_site1.ps1)

# Environment Variables
$companyName="Acme Inc"
$logFile="$env:tempjssReplication.Log"
$sourceFolder="D:JSSJSS_DP"
$distributionShare="DP_Share"
$distributionServers = "Server01","Server02","Server03","Server04"

# E-Mail Variables
$Global:emailBody = $null
$smtpServer = "smtp.acme.com"
$emailerName= "Casper DP Server"
$emailFrom = "JSS_Repl@acme.com"
$emailTo = "it@acme.com"
$emailSubject = "$env:computername JSS Replication Report"


Function logWrite ([string]$logString) {
# Write passed string to Log File
Add-content $logFile -value $logString

# Write passed string to Email Body
$Global:emailBody = $Global:emailBody + "$logString`r`n"

}

# Ensure a previous log file does not exist before starting
if(Test-Path -Path $logFile) {
Remove-Item $logFile
}

# Start by presenting header information
logWrite "$companyName JSS Replication Process..."
logWrite "--------------------------------------------------------------------------------"
$currentTime = Get-Date
logWrite "Started on $currentTime"
logWrite "Hostname: $env:computername"
logWrite "Master Folder: $sourceFolder"
logWrite "Distribution Servers:"
foreach ($server in $distributionServers) {logWrite "`t$server"}
logWrite "User: $env:username"
logWrite "--------------------------------------------------------------------------------"
logWrite "--------------------------------------------------------------------------------"

# Ensure the source Folder exists
if(Test-Path -Path $sourceFolder) {
# Loop through all Distribution Servers and use robocopy to replicate the Source Folder
foreach ($server in $distributionServers) {
$currentTime = Get-Date
logWrite "Replication to $server started at $currentTime"

$dpPath = "\$server$distributionShare"

$CaptureOutput = robocopy $sourceFolder $dpPath /R:1 /W:1 /COPY:DAT /E /PURGE /NP /NDL
$CaptureOutput | Out-File $logFile -Append -encoding UTF8

# Check if there was an error in copying files using robocopy
$Isfailure = $CaptureOutput -match "ERROR "
if ($Isfailure)
{
$response="FAILURES"
}
else
{
$response="SUCCESSFUL"
}

$currentTime = Get-Date
logWrite "Replication to $server completed at $currentTime"

logwrite " "

}
} else {
# Source Folder does not exist - Put the error in the email and the log file
logWrite "ERROR: Source Folder $sourceFolder does not exist!!"
}

logWrite "--------------------------------------------------------------------------------"
logWrite "--------------------------------------------------------------------------------"

logWrite " "

logWrite "--------------------------------------------------------------------------------"
logWrite "$response in copying $sourceFolder files to Distribution Point/s"
logwrite "Please look at the log file attached for more information."
logWrite "--------------------------------------------------------------------------------"

# Finish with Footer information
$currentTime = Get-Date
logWrite "Completed on $currentTime"
logWrite "--------------------------------------------------------------------------------"

$emailSubject = "$response`: $emailSubject"

# Send E-Mail with the log file as an attachment
Send-MailMessage -To $emailTo -Encoding ([System.Text.Encoding]::UTF8) -Subject $emailSubject -From "$emailerName <$emailFrom>" -Body $Global:emailBody -SmtpServer $smtpServer -Attachments $logFile

Error scanning method taken from;

Nithyanandam, S 2011, ‘Trap Robocopy errors within powershell script’, weblog post, 28 April, accessed 17 July 2012, <http://www.sanjeevnandam.com/blog/trap-robocopy-errors-within-powershell-script>.

---------
Update (17-10-2012): Script edited to use robocopy command with /PURGE instead of /MIR

Update (18-10-2012): Added emailer name field $emailerName

Update (12-04-2013): Added UTF8 encoding and Robocopy options /NP /ND to get the email and the log file to a much cleaner and clear formatting.

Update (17-04-2013): Added UTF8 encoding for email body and subject "-Encoding ([System.Text.Encoding]::UTF8)"

Update (22-10-2014): Added appending feature to the log file if you are replicating to multiple DPs so you'll get the log of all DPs in one log file. "$CaptureOutput | Out-File $logFile -Append -encoding UTF8"

---------

jwojda
Valued Contributor II

can this be used to copy DP's to other OSX servers?

brian_flynn
New Contributor III

@jwojda what os is the JSS and what kind of shares are your dp's?

We used to have our JSS on osx and dp's were windows. I used to have a similar script that ran on osx as a launch daemon that mapped drives and ran rsync to update our dp's (smb). I'm not sure a windows server can natively mount afp shares. But if you're using smb it shouldn't be much of an issue.

canopimp
New Contributor III

Just wanted to BUMP this post here saying the script still works and was very helpful.

dgreening
Valued Contributor II

We use MS DFS to replicate all out our Windows based distribution points. Works a treat!

bside
New Contributor II

+1 for DFS. Never had any issues with it.