User Tools

Site Tools


tsm:tdpve_scripts1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tsm:tdpve_scripts1 [2021/01/01 21:25]
127.0.0.1 external edit
tsm:tdpve_scripts1 [2022/01/27 17:17] (current)
manu
Line 8: Line 8:
 START /B dsmc backup vm "​SRVLNX2"​ -vmbackuptype=fullvm -mode=ifincremental -asnodename=DC1 -optfile="​C:​\Program Files\Tivoli\TSM\baclient\dsm.DC1_DM.opt"​ >> "​C:​\Program Files\Tivoli\TSM\baclient\dsmsched.DC1_DM.incr1.log"​ START /B dsmc backup vm "​SRVLNX2"​ -vmbackuptype=fullvm -mode=ifincremental -asnodename=DC1 -optfile="​C:​\Program Files\Tivoli\TSM\baclient\dsm.DC1_DM.opt"​ >> "​C:​\Program Files\Tivoli\TSM\baclient\dsmsched.DC1_DM.incr1.log"​
 </​cli>​ </​cli>​
 +
 +===== Script backup VM =====
 +
 +This script is planned to use with a linux datamover and powershell installed
 +<cli prompt='#'>​
 +[root@tdpvelnx]/​usr/​scripts # cat Backup-VM.ps1
 +</​cli>​
 +<​code>​
 +#​!/​usr/​bin/​pwsh
 +
 +<#
 +        .SYNOPSIS
 +            Backup ALL VM
 +        .OUTPUTS
 +            @{ExitCode=;​StdOut=,​StdErr=}
 +#>
 +
 +    # Global Parameters
 +    $VMvCenterName = '​vcenter01'​
 +    $VMvCenterUser = '​tdpve@vsphere.local'​
 +    $VMvCenterPass = '​xxxxxxxxxx'​
 +
 +    # TSM Parameters
 +    $Exclude_VM = @("​vmtest4","​vcenter01"​)
 +    $AsNode = '​DATACENTER'​
 +    $VMprod = @("​vmtest1:​vmdk=Hard Disk 1","​vmtest2:​vmdk=Hard Disk 1:vmdk=Hard Disk 2")
 +
 +
 +    Write-Verbose "​vCenter Name . . = $VMvCenterName"​
 +
 +
 +    #
 +    # Connect to vCenter
 +    #
 +    Write-Host "​Connecting to vcenter $($VMvCenterName)..."​
 +    try {
 +        Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -WarningAction SilentlyContinue -ParticipateInCeip $false -DisplayDeprecationWarnings $false -confirm:​$false
 +        $VCSession = Connect-VIServer -Server $VMvCenterName -User $VMvCenterUser -Password $VMvCenterPass
 +    }
 +    catch {
 +        write-host "Error to connect to vCenter $VMvCenterName."​
 +        exit -1
 +    }
 +
 +    ###
 +    ###     ​Retreive VM Information
 +    ###
 +    Write-Host "​Retreive VM information..."​
 +    $env:​LD_LIBRARY_PATH = "/​opt/​tivoli/​tsm/​client/​ba/​bin:/​opt/​tivoli/​tsm/​tdpvmware/​common/​jre/​jre/​bin/​classic"​
 +
 +    Write-Host "##### Backup VM Starting"​
 +    Foreach( $VM in $( Get-VM | Select-String -pattern $Exclude_VM ​ -notMatch)) {
 +    Write-Host "#### Backup VM: $VM"
 +    /​usr/​bin/​dsmc ba vm $VM  -optfile="/​opt/​tivoli/​tsm/​client/​ba/​bin/​dsm_ve.opt"​ -asnode="​$AsNode"​
 +    }
 +    Write-Host "##### Backup VM Finished"​
 +
 +    Write-Host "##### Backup specific VM Starting"​
 +    Foreach( $VM in $VMprod) {
 +    Write-Host "#### Backup VM: $VM"
 +    Write-Host /​usr/​bin/​dsmc ba vm $VM  -optfile="/​opt/​tivoli/​tsm/​client/​ba/​bin/​dsm_ve.opt"​ -asnode="​$AsNode"​
 +    /​usr/​bin/​dsmc ba vm $VM  -optfile="/​opt/​tivoli/​tsm/​client/​ba/​bin/​dsm_ve.opt"​ -asnode="​$AsNode"​
 +    }
 +    Write-Host "##### Backup specific VM Finished"​
 +
 +
 +    ###
 +    ###     ​Disconnect from vCenter
 +    ###
 +
 +    Disconnect-VIServer -Server $VMvCenterName -Confirm:​$false
 +
 +    exit $RC
 +
 +</​code>​
 +
 +===== Get disks backupped =====
 +
 +Check if all VM are backup and all disks
 +<cli prompt='#'>​
 +[root@mgmt01 scripts]# cat list_backup_vm.sh
 +</​cli>​
 +<​code>​
 +#!/bin/bash
 +#set -x
 +#
 +#@(#) send list of VM with exclusion
 +#
 +# version: 1.0 03-2021 Manu
 +#
 +# input file is generated on TDP VE datamover (linux)
 +# dsmc show vm all -optfile=dsm.opt -asnode=datacenter_01 > show_vm_all.txt
 +
 +dir=`dirname $0`
 +. $dir/.env
 +
 +# Variables
 +destination="​myemail@test.lu"​
 +
 +INPUT=$logpath/​show_vm_all.txt
 +logfile=$logpath/​output.csv
 +line=""​
 +
 +cat /dev/null > $logfile
 +
 +#​----------------------
 +get_input_file ()
 +{
 +ssh tdpve 'dsmc show vm all -optfile=dsm.opt -asnode=datacenter_01'​ > $INPUT
 +}
 +
 +#​----------------------
 +extract_vm ()
 +{
 +cat $INPUT | tr -s ' ' | sed 's/^\ //' | egrep '​^\(|^scheduleTagName|^VMDK'​ | sed 's/\ /\|/g' | grep -v '​|Copyright|'​ > ${INPUT}.1
 +for line1 in $(cat ${INPUT}.1)
 +do
 +  begin=$(echo $line1 | cut -d':'​ -f1 | sed '​s/​$/:/'​)
 +  end=$(echo $line1 | cut -d':'​ -f2- | sed '​s/​^|//'​)
 +  if [ "​$(echo $begin | grep '​^('​ | grep '​.vmName:'​ > /dev/null; echo $?)" -eq "​0"​ ]
 +  then
 +    if [ "​${line}"​ != ""​ ]
 +    then
 +      echo $line | sed 's/|/\ /g' >> $logfile
 +    fi
 +    vm_name=$(echo $line1 | cut -d':'​ -f2- | sed '​s/​|//'​)
 +    line="​${vm_name}"​
 +  else
 +    if [ "​$(echo $begin | grep '​^scheduleTagName:'​ > /dev/null; echo $?)" -eq "​0"​ ]
 +    then
 +      tag=$(echo $end)
 +      line="​$line;​$tag"​
 +    else
 +      if [ "​$(echo $begin | grep '​VMDK\['​ > /dev/null; echo $?)" -eq "​0"​ ]
 +      then
 +        if [ "​$(echo $begin | grep '​\]Label:'​ > /dev/null; echo $?)" -eq "​0"​ ]
 +        then
 +          disk=$(echo $end)
 +        else
 +          if [ "​$(echo $begin | grep '​\]Status:'​ > /dev/null; echo $?)" -eq "​0"​ ]
 +          then
 +            status=$(echo $end)
 +            line="​$line;​$disk;​$status"​
 +          fi
 +        fi
 +      fi
 +    fi
 +  fi
 +
 +done
 +echo "​$line"​ >> $logfile
 +}
 +
 +#​----------------------
 +sendemail ()
 +{
 +echo "###########​ sendemail"​
 +SIZE=$(cat $logfile | wc -l)
 +
 +if (( SIZE > 6 ))
 +then
 +  date "​+%d-%m-%Y"​ | mailx -a $logfile -s "List VM backup by ISP" $destination
 +  exit 1
 +else
 +  echo " "
 +  echo No error
 +  echo " "
 +  exit 0
 +fi
 +}
 +
 +#########################​
 +# Main
 +#########################​
 +main ()
 +{
 +date
 +get_input_file
 +extract_vm
 +#sendemail
 +#rm ${logfile}* 2>/​dev/​null
 +}
 +
 +main > $logname 2>&1
 +</​code>​
 +
 +output like:
 +<cli prompt='#'>​
 +vm1;​VM_INCR_TUE;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Excluded - User
 +VM2;​VM_INCR_FRI;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Included
 +linux1;​VM_INCR_WED;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Included
 +linux2;​VM_INCR_FRI;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Included
 +winvm01;​VM_INCR_FRI;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Included
 +winvm02;​Unassigned;'​Hard disk 1' (Hard Disk 1);​Included;'​Hard disk 2' (Hard Disk 2);Included
 +</​cli>​
 +
 +If no scheduletag is assigned to the VM, then no backup. Some disks are also excluded from some VMs.
tsm/tdpve_scripts1.1609532731.txt.gz ยท Last modified: 2021/01/01 21:25 by 127.0.0.1