Kiln » KilnSupportScripts Powershell Scripts to help monitor a Kiln environment. Contact Fog Creek support before using. Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

adding script from customer to copy KilnRepositories as a nightly backup

Changeset 13315a17166d

Parent b458cec4be8a

by Profile picture of User 476Ben McCormack <benm@fogcreek.com>

Changes to one file · Browse files at 13315a17166d Showing diff from parent b458cec4be8a Diff from another changeset...

Change 1 of 1 Show Entire File misc/​copyKilnRepositories.ps1 Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
 
@@ -0,0 +1,64 @@
+# This script was provided by a customer for backing up the KilnRepositories +# directory. It can be set up as a Windows Scheduled Task and run daily +# to copy the entire directory to a different location. It shuts down +# all appropriate services and processes before beginning the copy. +# +# NOTE: Newer versions of Kiln may use different services and processes, +# so make sure that the list is complete. + +# Live values +$servicesToStop = "Apache Tomcat 6", "FogBugz Maintenance Service", "Kiln Queuing Service", "KilnStorageService", "W3SVC" +$processesToEnsureStopped = "backend", "FogBugzMaint", "QueueService", "redis-server", "tomcat6", "memcached" +$processTimeoutSeconds = 60 +$backupLogLocation = "E:\Backup Scripts" +$liveRepoLocation = "D:\KilnRepositories" +$cloneRepoLocation = "E:\Kiln Backup" +$backupRepoLocation = "\\somewhere-on-network\Kiln Backup" +$smtpServer = "smtp.yourserver.com" +$fromEmail = "from@example.com" +$toEmail = "to@example.com" + +# Start logging output, so we can send it in the email +Start-Transcript -Path "$backupLogLocation\BackupScript.txt" + +# Stop all the services. +$servicesToStop | Stop-Service + +# Give everything a little time to stop before we have to forcefully shut +# them down. +Start-Sleep -s $processTimeoutSeconds + +# Kill any remaining processes, to ensure we can get a consistent snapshop. +# Necessary evil! :( +Stop-Process -Name $processesToEnsureStopped -ErrorAction SilentlyContinue + +# Clone the repos to the other local drive (to minimise downtime, this is +# faster than copy to network!). +robocopy "$liveRepoLocation" "$cloneRepoLocation" /MIR /MT /W:3 /R:100 /LOG:"$backupLogLocation\BackupKiln.txt" + +# Bring the services back up. +$servicesToStop | Start-Service + +# Copy the repos over to the network location. +robocopy "$cloneRepoLocation" "$backupRepoLocation" /MIR /MT /W:3 /R:100 /LOG:"$backupLogLocation\CopyToNetwork.txt" + +# Stop logging output, so we can embed it in the email. +Stop-Transcript + +# Email the resulting logs. +$smtp = new-object Net.Mail.SmtpClient($smtpServer) +$msg = new-object Net.Mail.MailMessage + +$msg.From = $fromEmail +$msg.To.Add($toEmail) +$msg.subject = "Kiln Automated Backup" +$msg.body = [string]::Join("`r`n",(Get-Content "$backupLogLocation\BackupScript.txt")) + +$logfile1 = new-object +Net.Mail.Attachment("$backupLogLocation\BackupKiln.txt") +$logfile2 = new-object +Net.Mail.Attachment("$backupLogLocation\CopyToNetwork.txt") +$msg.Attachments.Add($logfile1) +$msg.Attachments.Add($logfile2) + +$smtp.Send($msg) \ No newline at end of file