2012年3月23日 星期五

壓縮SQL Server的Transation Log


記錄一下..免得久久找一次.
有用的方法來抑制SQL DB的Log快速成長:
1. 不重要的DB,將Recovery Mode 改為Simple:DB->properties->options (自動記錄截斷)
2. 壓縮Transaction Log DB:
壓縮SQL Server的Transation Log(交易記錄檔)
USE <DB_NAME>   --<DB_NAME>:資料庫名稱
DBCC SHRINKFILE([<DB_NAME>_log],2)    --<DB_NAME>_log:ldf檔的邏輯檔名

Ex: 壓縮OCS DB的Log
USE OCSDB
DBCC SHRINKFILE(OCSDB_log],2)

更多說明可看出處:http://msdn.microsoft.com/zh-tw/library/ms345583.aspx

2012年3月14日 星期三

Terminal Server 內的檔案為什麼不能刪檔案?

Windows 2008 ˉTerminal Server有時多人登入後,不知道為什麼偏偏有一個檔案不能刪,
點選刪除時,出現 Access is denied.
點選檔案右鍵=>[屬性Properties]=>[安全Security] =>[進階Advanced]=>
[Permissions]標籤 =>顯示 you do not have permission to view or edit this object's permission settings
[擁有者/Owner] 標籤=> [編輯/Edit] => [Change owner to] 挑選新Owner => [套用/Apply]
也無法變更。

明顯是某個執行中的程式正咬住,但又不知是誰?
安裝 Unlocker 1.19 後,http://download.cnet.com/Unlocker/3000-2248_4-10493998.html
點選檔案右鍵=> unlocker =>即顯示Lock檔案的程式/程序ID(pid)/執行者等資訊.
請相應使用者退出後即可刪除.

2012年3月8日 星期四

如何整批啟用Lync User及更改設定?

整批更新Lync User,簡單的更新可以用Command 方式處理, 複雜的更新只能用批次處理:



1.    啟用Lync : 單一用戶(以LyncUser1為例)
Enable-CsUser -Identity "LyncUser1" -RegistrarPool pool.lync.com -SipAddress sip:lyncuser1l@lync.com

2.      啟用Lync : 以OU整批啟用
Get-CsAdUser -OU "ou=demo,dc=lync,dc=com" | Enable-CsUser -RegistrarPool " pool.lync.com " -SipAddressType EmailAddress -SipDomain lync.com

3.     啟用LyncUser1的 Enterprise Voice
      Set-CsUser -Identity "CN=lyncuser1,OU=demo,dc=lync,dc=com" -EnterpriseVoiceEnabled $True -LineURI tel:+8001


4.    整批啟用Enterprise Voice, 試了很久, 最簡單的方式是用PowerShell: 
需有一個Shell script : 例如: demo.ps1 
匯入資料: 例如: user.csv 
輸出結果到執行目錄上: AssignLineUri-yyyy-mm-dd-xxxx.txt 型式


a.將下列資訊存成: demo.ps1 

param( [string] $importfile = $(Read-Host -prompt "Please enter a file name"))
$importedusers = Import-Csv $importfile

$transcriptname = "AssignLineUri-" + (Get-Date -Format s).replace(":","-") +".txt"

Start-Transcript $transcriptname

foreach ($importeduser in $importedusers)
    {
        $UserDN = "CN=" + $importeduser.SIPUser + ",OU=demo,dc=lync,dc=com"
Set-CsUser -identity $UserDN -EnterpriseVoiceEnabled $True -LineUri $importeduser.LineUri –Verbose
    }
Stop-Transcript



b.將使用者資訊及話機號碼設成: User.csv

SIPUser,LineUri
lyncuser1,tel:+8001
lyncuser2,tel:+8002


c. 操作方式: 
於Start =>Lync Server management shell => <shell directory>\demo.ps1 
輸入: user.csv 
查看結果





其他簡體的啟用範例: 
http://bbs.winos.cn/archiver/tid-117393.html


PowerShell 的啟用範例: 
http://blogs.technet.com/b/csps/archive/2010/06/10/scriptmoveusers.aspx
http://blogs.technet.com/b/csps/archive/2010/06/10/scriptassignlineuris.aspx

2012年2月23日 星期四

如何將 Lync 與 FreePBX/ Trixbox 整合


花很多時間將 Lync 2010 FE 透過 Lync Mediation Server 連接FreePBX( Trixbox),如果沒有做成文件,以後一定會找不到。

所需的東西:
1. TrixBox (目前可抓到 Trixbox 2.8.0.4 CE) , 相關說明如下
http://www.diybl.com/course/6_system/linux/Linuxjs/2008106/148288.html
http://www.msexchange.org/articles_tutorials/exchange-server-2010/mobility-client-access/how-configure-unified-messaging-asterisk-sip-gateway-part2.html

2. Client : 3CXPhone
http://www.3cx.com/VOIP/voip-phone.html

3. TrixBox 設定方法:
http://www.fintechcommunications.com/blog/?p=60
http://imaucblog.com/archive/2009/10/03/part-1-how-to-integrate-exchange-2010-or-2007-with-trixbox-2-8/

4. Lync 設定方法:
http://www.circuitid.com/blog/lync-setup-guide-using-circuitid-part-1-configuring-mediation-server
http://www.circuitid.com/blog/lync-setup-guide-using-circuitid-part-2-configuring-voice-routing

5. 注意事項:
Lync 內部都走E.164 (+開頭的Formate,例如:+2015),如果透過SIP Trunk丟給PBX時,有的FreePBX 不接受"+"號,需將+號移除。

這個動作在Lync 叫 : Outbound route translation ,(說明請看:Translating Outbound dials strings)
http://technet.microsoft.com/en-us/library/gg412757.aspx
http://technet.microsoft.com/en-us/library/gg425831.aspx
http://blogs.technet.com/b/csps/p/uimap59.aspx

如果效果是要將E.164 的formate (例如:+2015) 往 PSTN Gateway 送時,就會取消"+",為 2015 。  
則可於Trunk Configuration 內這樣設定:
Starting digits = +2 : 開頭為+2
Length= exactly 5 : 這裡的Length 是說含加號,共五碼 (例如: +2015)
Digits to remove = 1 : 移除第一碼,即加號
Digits to add = "": 不加上任何字元
http://designinglync.blogspot.com/2011/05/lync-dial-plans-and-normalization-rules.html

6. 語音/視訊通訊最低頻寬說明:
http://technet.microsoft.com/zh-tw/library/gg398334.aspx

7. Trixbox 有用的說明
http://www.freepbx.org/support/documentation/howtos/howto-setting-up-voip-provider-trunks/freepbx-sip-trunks-powered-by-ban

2012年2月7日 星期二

archive system log by schedule tasks


' 由於某些軟體會產生大量的檔案,特建立備存機制,
' 1. 將特定目錄下的子目錄都備存起來,並刪除空的子目錄
' 2. 需先安裝WINRAR
' 3. 將下列程式做成.vbs 檔案
' 4. 建立Task schedule , 將備存的目錄設為參數
'
'--- .vbs 程式開始
Option Explicit
 
' 宣告變數
Dim FSO, agoDays, modifiedDate, ArcFolder  ,myArgs, GetDateTimeFM, wshshell

' 建立檔案系統物件(File System Object)
Set FSO = CreateObject("Scripting.FileSystemObject")
' 建立執行的shell 物件
Set wshshell=createobject ("wscript.shell")
'取得第一個變數
Set myArgs = WScript.arguments
' 欲備存檔案所在之目錄    
ArcFolder = myArgs(0)
' 取得日期(yyyy_mm_dd_hh_nn_ss)
GetDateTimeFM = GetFormattedDateTime()

' 呼叫備存檔案的子程序
ArcFilesInFolder FSO.GetFolder(ArcFolder)    

' 呼叫刪除空Folder的子程序
DelFoldersInFolder FSO.GetFolder(ArcFolder)    

' 備存目錄的子程序
Sub ArcFilesInFolder(folder)
  ' 宣告變數
  Dim file, subFolder,strshell
  ' 如果遇到子目錄,也要進去檢查並刪除
  For Each subFolder in folder.SubFolders
      strshell = "WinRAR.exe a -r -df " + SubFolder + "-dt-" + GetDateTimeFM + ".rar " + subFolder + "\"
      Call wshshell.run (strshell,0)
Next
End Sub  

' 刪除檔案的子程序
Sub DelFoldersInFolder(folder)
  ' 宣告變數
  Dim dfile, dsubFolder, fdEmpty  
  ' 如果遇到子目錄,要先進去檢查並刪除
  For Each dsubFolder in folder.SubFolders
      DelFoldersInFolder dsubFolder
Next  
  fdEmpty = True
  ' 找出目前所在目錄內所有的檔案
  For Each dfile In folder.Files ' 檢查檔案日期是否符合條件,若符合,就刪除
      fdEmpty = False
  Next    
  For Each dsubFolder in folder.SubFolders
  fdEmpty = False
    Next
    If fdEmpty = True Then
    folder.delete
  End If
End Sub  

' 取得日期的函式
Function GetFormattedDateTime
  Dim strNow, strDD, strMM, strYYYY,strHH,strNN,strSS
strYYYY = DatePart("yyyy",Now())
strMM = Right("0" & DatePart("m",Now()),2) 'month
strDD = Right("0" & DatePart("d",Now()),2) 'day
strHH = Right("0" & DatePart("h",Now()),2) 'hour
strNN = Right("0" & DatePart("n",Now()),2)  'mintue
strSS = Right("0" & DatePart("s",Now()),2) 'second
GetFormattedDateTime = strYYYY & "_" & strMM & "_" & strDD & "_" & strHH & "_" & strNN & "_" & strSS
End Function
'--- .vbs 程式結束

2012年2月6日 星期一

How to archive Discussion Application in Lotus Notes?

開發過Lotus Notes 應用系統系統的都知道,只要文件Copy再貼上,@DocumentUnid 一定不一樣,因次,應用系統通常都會自己建一個 UniqueID 欄位,來處理文件複製/貼上而造成相關文件對應不起來的這種問題。

但是, Discussion 是一個特別的資料庫,它是討論區,既然是"討論",就會有前/後(主文/回應/回應的回應)的問題,除非所有預設的View 都再客制,否則無法以自製 UniqueID來處理前/後文關係,因此通常都不再客制Document ID欄位。

這時後的備存,只能使用系統預設的備存工具,來保留資料移動到不同系統/目錄時,仍能有相同的Document ID。

1. 先設定Archiving Rule : Database => Properties => Archive Setting => Archive settings 設定視窗
   Basics => 設定目的地 (A Server 到 B Server )
   Criteria => 同Mail , 設定那些目錄需備存
   Advanced => 正常備存後刪除
   Schedule => 不能設...怎麼辦? 
2. 設定代理程式,自動啟動備存排程: 
Dim s As New notessession
Dim db As notesdatabase
Set db = s.currentdatabase
Call db.archiveNow()
Exit Sub

2012年1月19日 星期四

每天自動刪除過期檔案(Delete Files over than n days)

File Server 雖是儲存空間,但也不必要永久存放,如果已經進磁帶備份後,很多參考用的大檔案是可以刪除的。

研究了一下 VBScript 自動刪除的機制,將下面的.vbs File 加到Server 的Schedule Tasks ,再加上絕對路徑當參數,就可以自動刪除了。

------------------ 以下作成一個 delFolderFilesOverThan60days.vbs --------


' 指定所有變數必須事先宣告才能使用
Option Explicit
 
' 宣告變數
Dim FSO, agoDays, modifiedDate, delFolder  ,myArgs

'If WScript.arguments.length <> 0 Then
' WScript.quit  
'End If

' 建立檔案系統物件(File System Object)
Set FSO = CreateObject("Scripting.FileSystemObject")

' 請將下面的變數值換成你要的
' 指定 n 天前的檔案,現在是 3 天前
agoDays = 60
' 取得檔案的修改日期
modifiedDate = DateAdd("d", -agoDays, Date)  

Set myArgs = WScript.arguments

' 欲刪除檔案所在之目錄    
delFolder = myArgs(0)

' 呼叫刪除檔案的子程序
DelFilesInFolder FSO.GetFolder(delFolder)    

' 刪除檔案的子程序
Sub DelFilesInFolder(folder)
  ' 宣告變數
  Dim file, subFolder
 
  ' 找出目前所在目錄內所有的檔案
  For Each file In folder.Files
      ' 檢查檔案日期是否符合條件,若符合,就刪除
      If ((file.DateLastModified <= modifiedDate)) Then
          file.delete
      End If
  Next
 
  ' 如果遇到子目錄,也要進去檢查並刪除
  For Each subFolder in folder.SubFolders
      DelFilesInFolder subFolder
Next
End Sub  
 
'WScript.Echo("作業執行完畢:" & Date & " " & Time)

----------------------------------

程式的參考出處:

http://ithelp.ithome.com.tw/question/10009001
http://ithelp.ithome.com.tw/question/10058183