如何克隆 (Clone/Convert) Ubuntu 實體主機

公司最近採購了一台主機裝 Ubuntu 12.04 LTS,上面的資料被要求要做例行性的備份,因為那台主機的所有權不在我們部門,所以拿來做 Cluster 也不實際,想了想要保留固定時間的資料,又能要在必要時取代原來的機器,把他轉成虛擬化就是一個不錯的選擇。

 

首先 Ubuntu 裝好之後是沒有設定 root 的密碼,所以要人為指定,之後才可以取得本機最高權限,其指令如下:

sudo passwd root

 

同時提醒啟動 (Enable) root 帳號可能導致很多不正常的現象,啟動時要自己負責喔,建議平常還是依原使用方式使用,當作 root 帳號還是不存在。

Alter for enabling root account
Alter for enabling root account

資料來源: https://help.ubuntu.com/community/RootSudo

閱讀全文 如何克隆 (Clone/Convert) Ubuntu 實體主機

撈取 DNS 紀錄寫到資料庫

最近因任務需要在網域內把 IP 轉成電腦名稱,通常這個可以利用 nslookup 指令來達成,但是需要由 Excel 報表內呈現就有點難度。

 

所以我想出來的解決方案是去網域內的 DNS 控制器去撈所有的紀錄,然後把它寫回到資料庫內,這樣在做 SQL Query 時就可以很快速的撈取出來,靠先前開發的 VBScript 來做改良。

 

主要的抓取 DNS 紀錄的原始碼還是由 http://gallery.technet.microsoft.com/scriptcenter/8ebcaa52-f5c0-4fc1-99fe-d1c8798fddf4 微軟的網站找到的,我只是修正抓到資料後回寫到資料庫去。

首先建立一個很簡單的資料表 (table),可以參考底下的指令來產生

 

CREATE TABLE “YourSchemaName”.”IP_COMPNAME”

  (

    “IP_ADDR”   VARCHAR2(16 BYTE) NOT NULL ENABLE,

    “COMP_NAME” VARCHAR2(50 BYTE) NOT NULL ENABLE,

    “FQDN”      VARCHAR2(100 BYTE),

    CONSTRAINT “IP_COMPNAME_PK” PRIMARY KEY (“IP_ADDR”, “COMP_NAME”) USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE “WEBAP_TBS” ENABLE

  )

  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE

  (

    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT

  )

  TABLESPACE ” YourSchemaTableSpace” ;

 

再把底下這一段 VB Script 貼到檔案去, 命名成 GetDNS.vbs

‘for standard query

const cnstCommand = 1

 

Dim IPAdd

Dim Computer

strComputer = “YourDNSServer”

 

‘ 設定連線字串

connectionString = “DRIVER={Microsoft ODBC for Oracle};SERVER=Oracle;User Id=yourschemaName;Password=YourPassword;”

Set connection = CreateObject(“ADODB.Connection”)

Set theCommand = CreateObject(“ADODB.Command”)

connection.Open connectionString

 

 

 

Set objWMIService = GetObject(“winmgmts:” & strComputer & “rootMicrosoftDNS”)

Set colItems = objWMIService.ExecQuery( “SELECT * FROM MicrosoftDNS_PTRType”,,48)

For Each objItem in colItems

 

    CompNameArray = Split(objItem.RecordData ,  “.”)

    For i = LBound(CompNameArray) to UBound(CompNameArray)

    Computer = CompNameArray(0)

    Next

 

 

    IPAddArray = Split (objItem.OwnerName , “.”)

    

    For i = LBound(IPAddArray) to UBound(IPAddArray)

    IPAdd = IPAddArray(3) & “.” & IPAddArray(2) & “.” & IPAddArray(1) & “.” & IPAddArray(0)

    Next

   

               

‘ 清除掉先前記錄的資料

               

        cmdStr = “DELETE FROM WEBAP.IP_COMPNAME WHERE IP_ADDR = ‘” & IPAdd & “‘”

        WScript.Echo “Clear ” & IPAdd &”‘s DNS Record”

        thecommand.CommandText = CmdStr

        theCommand.ActiveConnection = connection

        theCommand.Execute

               

      ‘ 製作 SQL Command

        CmdStr = “INSERT INTO WEBAP.IP_COMPNAME (IP_ADDR, COMP_NAME, FQDN) VALUES (‘”

        CmdStr = CmdStr & IPADD & “‘, ‘” & Computer & “‘, ‘”

        CmdStr = CmdStr & objItem.RecordData & “‘) “

               

 

        ‘ 執行 SQL 指令

    ‘WScript.Echo cmdstr

        thecommand.CommandText = CmdStr

        thecommand.CommandType = cnstCommand

        thecommand.ActiveConnection = connection

        thecommand.Execute            

               

 

Next

 

Set Connection = nothing

set thecommand = nothing

 

 

 

Set objFSO = Nothing

Set objFile = Nothing

Set objWMIService = Nothing

Set colItems = Nothing

 

 

需要執行他時,只要在 DOS BOX 打入 CScript GetDNS.vbs 即可,執行時間隨DNS紀錄的多寡有所不同,應該在幾分鐘之內就可以跑完