背景信息:
創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括南充網(wǎng)站建設(shè)、南充網(wǎng)站制作、南充網(wǎng)頁制作以及南充網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,南充網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到南充省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
我們的數(shù)據(jù)存放位置有三個,本地、同城、異地。備份數(shù)據(jù)會放本地,然后常規(guī)通過DFS同步到同城、異地兩個地方。由于DFS的特性是雙向同步的,所以你如果在一個地方刪除、更新文件,那么三個地方是會同步更新成一致的。
由于數(shù)據(jù)量的大小的限制,我沒有辦法無限制的保存數(shù)據(jù)在服務(wù)器上,因此會定期把舊備份刪除。但是我異地的服務(wù)器的本地硬盤又比較大,我又想差異化的把歷史數(shù)據(jù)最大限度的在異地服務(wù)器上進(jìn)行保存。
解決方案:
File Server Resource Manager 的File Managerment Task 功能可以針對文件的創(chuàng)建日期、修改日期或者自定義分類屬性進(jìn)行過濾,并且執(zhí)行自定義action. 這里的自定義action 我們使用powershell 腳本。
powershell 腳本針對過濾出的文件在另外一個目錄對源文件執(zhí)行mklink /H 操作(創(chuàng)建硬鏈接,硬鏈接的好處是如果DFS目錄下的文件刪除了,實(shí)際的文件是不會刪除的,因?yàn)檫€有一個硬鏈接引用實(shí)際的文件數(shù)據(jù),硬鏈接會比Copy更快,IO會非常?。?/p>
File Server Resource Manager 自帶報告功能,因此可以對操作過的文件進(jìn)行報告生成。
創(chuàng)建一個分類屬性IsHardLinkCreated ,這個屬性我們用來過濾篩選沒有hardlink 過的文件(powershell 腳本會在hardlink 文件后,設(shè)置這個屬性)。
在c:\scripts\makelink.ps1 中做下面文件內(nèi)容
param([string]$FileSource, [string]$FolderDestination) # Capture source folder name and filename $SourceFileName = (Get-Item $FileSource).Name $SourceFolder = (Get-Item $FileSource).DirectoryName # Destination Path $DestinationPath = $FolderDestination + "\" + $SourceFolder.Substring(3, $SourceFolder.Length-3) # Check Destination Path, create if doesn't exist $CheckedPath = Get-Item $DestinationPath -ErrorAction SilentlyContinue if ($CheckedPath -eq $null) { New-Item -Path $DestinationPath -ItemType Directory |Out-Null } $destFile=$DestinationPath + "\" + $SourceFileName # test whether dest file exist ,if exist delete it . if(test-path $destFile){ Remove-Item -Path $destFile -Force } # Move original file # Move-Item -Path $FileSource -Destination $DestinationPath -Force # Create Hard link to origin file in destation folder $expr = Invoke-Expression -Command ("cmd /c mklink /H `"" + $destFile + "`" `"" +$FileSource + "`"") # Please create Classification properties in File server resource manager named IsHardLinkCreated first $cls = New-Object -com Fsrm.FsrmClassificationManager $cls.setFileProperty($FileSource,"IsHardLinkCreated",1) $cls=$nothing
創(chuàng)建File Management Tasks 的powershell 腳本。c:\scripts\CreateFSRMTask.ps1
$Command = "C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe" $CommandParameters = "`"C:\scripts\MakeLink.ps1 -FileSource '[Source File Path]' -FolderDestination 'E:\Expired'`"" $Action = New-FSRMFmjAction -Type Custom -Command $Command -CommandParameters $CommandParameters -SecurityLevel LocalSystem -WorkingDirectory "C:\Windows\System32\WindowsPowerShell\v1.0\" $Condition = New-FsrmFmjCondition -Property "File.DateCreated" -Condition LessThan -Value "Date.Now" -DateOffset -5 $condition2=New-FsrmFmjCondition -Property "IsHardLinkCreated" -Condition NotExist $Schedule = New-FsrmScheduledTask -Time (Get-Date) -Weekly Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday New-FsrmFileManagementJob -Name "Make Hard Link of old files" -Namespace "E:\DR_FromSZ" -Action $Action -Condition $Condition,$condition2 -Schedule $Schedule
另外已經(jīng)做過hardlink的文件會標(biāo)記分類
這個時候即使DFS目錄的源文件被刪除,做了hardlink 的Expired 子目錄下的文件也還存在。
參考信息:
https://blogs.technet.microsoft.com/filecab/2009/05/11/customizing-file-management-tasks/
https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.storage.fsrmclassificationmanagerclass.setfileproperty(v=vs.85).aspx
總結(jié):
hardlink 如果創(chuàng)建后,源文件刪除,再在源位置創(chuàng)建同名文件,目標(biāo)文件不會更新,這個時候如果要再創(chuàng)建hardlink ,需先刪除目標(biāo)。
由于這個powershell 的自定義任務(wù)我感覺是順序執(zhí)行,而且針對每個文件調(diào)用一次powershell腳本,所以效率不是很高,但是對于備份后的大文件應(yīng)該問題不大(因?yàn)榇蟛糠窒到y(tǒng)一天也就幾個大的備份文件),如果是很多小文件,執(zhí)行時間就估計(jì)會比較慢。
本文題目:使用FSRM的Task的自定義Action功能并利用Hardlink功能來備份數(shù)據(jù)
鏈接URL:http://aaarwkj.com/article28/pespcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、小程序開發(fā)、網(wǎng)站制作、網(wǎng)站營銷、外貿(mào)網(wǎng)站建設(shè)、虛擬主機(jī)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)