행복님 avatar

Minio 통해 SQLSERVER 2차 백업 구성

jaerakson

Published: 02 Oct 2018 › Updated: 02 Oct 2018Minio 통해   SQLSERVER 2차 백업 구성

Minio 통해 SQLSERVER 2차 백업 구성

Minio 통해 SQLSERVER 2차 백업 구성

Minio 서버는 2차 백업용 서버 별도로 구축 하셔야 합니다.

아래의 URL 보시면 쉽게 구축 가능합니다.
https://docs.minio.io/docs/minio-quickstart-guide

환경
windows , Powershell , minio ,mc

minio 설치 및 가이드
https://docs.minio.io/docs/minio-quickstart-guide

Minio Client 설치 및 가이드
https://github.com/minio/mc

아래의 2개 파일 생성 후

파워셀에서 호출 하면 됩니다.
호출 예제


Powershell.exe -noprofile -executionpolicy bypass -file "E:\Backup\BackupUpload.ps1" "E:\Backup\BackupUpload.ini"


ini (BackupUpload.ini) 파일 설정을 통해 2차 백업 및 파일 삭제

BackupUpload.ini

 
/*
[File] --백업 파일 선택 및 삭제 (S3,Minio)
S3DelDay -- S3 삭제 주기 (일자만큼 보관)
GetTime   -- 로컬백업  시간 2 현재시간 기준으로 2시간 전 이후 백업 리스트
 
[Backup]  백업 경로
S3buckkeyDir S3,Minio  경로 (2차 백업 보관 경로)
[S3] S3,Minio  경로
*/
 
[File]
S3DelDay=2
GetTime= 2
 
[Backup]
SystemBackupDir= E:\backup\System
DBBackupDir= E:\backup\FULL
TRNBackupDir= E:\Backup\TRN
S3buckkeyDir= minio/dbbackup/maindb
 
[S3]
IP =  10.10.10.100
Port=  9000
Key =    xxxxx
SECRET =  xxxxxxx


백업 스크립트
BackupUpload.ps1


<#

--------------------------------------------------------------------------------------------------------------------------------------------------------
-- Powershell.exe -noprofile -executionpolicy bypass -file  "E:\Backup\BackupUpload.ps1" "E:\Backup\BackupUpload.ini"
--------------------------------------------------------------------------------------------------------------------------------------------------------
$inifile = "E:\Backup\minioBakup.ini"
 
 param (
 [String]$inifile )
#>
$inifile = "E:\Backup\BackupUpload.ini"
 
 
$S3DelDay ="";$GetDay=""
$SystemBackupDir="";$DBBackupDir=";$TRNBackupDir=";$MiniobuckkeyDir=""
$IP ="";$Port="";$Key ="";$SECRET =""
  
   
  
    $ini = @{}
    switch -regex -file $inifile
    {
        "^\[(.+)\]" # Section
        {
            $section = $matches[1]
            $ini[$section] = @{}
            $CommentCount = 0
        }
        "^(;.*)$" # Comment
        {
            $value = $matches[1]
            $CommentCount = $CommentCount + 1
            $name = "Comment" + $CommentCount
            $ini[$section][$name] = $value
        }
        "(.+?)\s*=(.*)" # Key
        {
            $name,$value = $matches[1..2]
            $ini[$section][$name] = $value
        }
    }
  
   
 
 
$S3DelDay=  $($ini["File"]["S3DelDay"]) -replace " ",""
$GetTime   =  $($ini["File"]["GetTime"]) -replace " ",""
   
$SystemBackupDir=  $($ini["Backup"]["SystemBackupDir"]) -replace " ",""
$DBBackupDir=  $($ini["Backup"]["DBBackupDir"]) -replace " ",""
$TRNBackupDir= $($ini["Backup"]["TRNBackupDir"]) -replace " ",""
$S3buckkeyDir=  $($ini["Backup"]["S3buckkeyDir"]) -replace " ",""
  
$IP =   $($ini["S3"]["IP"]) -replace " ",""
$Port=  $($ini["S3"]["Port"]) -replace " ",""
$Key =    $($ini["S3"]["Key"]) -replace " ",""
$SECRET =   $($ini["S3"]["SECRET"]) -replace " ",""
 
$S3DelDay ;$GetTime
$SystemBackupDir;$DBBackupDir;$TRNBackupDir;$MiniobuckkeyDir
   
$IP ;$Port;$Key ;$SECRET
 
$GetDate =  (Get-Date).AddHours(-$GetTime)
 
mc config host add minio  "http://$($IP):$($Port)"  $($Key)  $($SECRET) S3v4 
 
 
 
$Minio =@{}
# System Backup
$Minio= @(get-childitem -path $SystemBackupDir -Recurse | Where-Object { [DateTime]$_.LastWriteTime -ge ($GetDate ) -and (  $_.Name -like "*.bak") } | select-Object -property  fullname ,name )
for ($i=0; $i -le  $Minio.length-1   ; $i++)  {
    # $Minio[$i].fullname
    mc cp  $Minio[$i].fullname  "$($S3buckkeyDir)/SYSTEM/"
}
  
#Full Backup
$Minio= @(get-childitem -path  $DBBackupDir  -Recurse | Where-Object { [DateTime]$_.LastWriteTime -ge ($GetDate ) -and (  $_.Name -like "*.bak") } | select-Object -property  fullname ,name )
for ($i=0 ; $i -le  $Minio.length-1  ; $i++)  {
    $Minio[$i].fullname
    mc cp  $Minio[$i].fullname  "$($S3buckkeyDir)/FULL/"
}
  
#Trn Bakcup
$Minio=@(get-childitem -path $TRNBackupDir -Recurse | Where-Object { [DateTime]$_.LastWriteTime -ge ($GetDate ) -and (  $_.Name -like "*.trn") } | select-Object -property  fullname ,name  )
 for ($i=0 ; $i -le  $Minio.length-1  ; $i++)  {
    mc cp  $Minio[$i].fullname  "$($S3buckkeyDir)/TRN/"
}
 
 
<#
      
$MinioDel= @{}
$MinioDel =  $(mc ls $MinioPath\SYSTEM).split(' ') | where-object {$_ -like '*2018_03_15*'}
 
 
 for ($i=0; $i -lt  $MinioDel.Length  ; $i++)  {
    "$($MinioPath)/TRN/$($MinioDel[0])"
     
    mc rm "$($MinioPath)/TRN/$($MinioDel[0])"
}
 
#>
 
 mc rm --recursive --force --older-than=$S3DelDay $S3buckkeyDir
 
mc ls $S3buckkeyDir\SYSTEM
mc ls $S3buckkeyDir\FULL
mc ls $S3buckkeyDir\TRN

Leave Minio 통해 SQLSERVER 2차 백업 구성 to:

Written by

Read more #kr posts


Best Posts From 행복님

We have not curated any of jaerakson's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From 행복님