Update 'all'
This commit is contained in:
parent
2e797647a2
commit
1848e74ac8
1 changed files with 45 additions and 24 deletions
69
all
69
all
|
@ -5,13 +5,13 @@
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
# Setting path for vboxmanage
|
# Setting path for vboxmanage
|
||||||
$virtualBoxPath = "c:\Program Files\Oracle\VirtualBox"
|
$Env:Path = "c:\Program Files\Oracle\VirtualBox\"
|
||||||
|
|
||||||
# creating backup paths
|
# creating backup paths
|
||||||
$remoteBackupPath = "\\freenas\programas\VM_Backup\"
|
$remoteBackupPath = "\\freenas\programas\VM_Backup"
|
||||||
$backupDriveLetterMount = "L:"
|
$backupDriveLetterMount = "L"
|
||||||
$backupFilename = $backupDriveLetterMount + "\" + [string](Get-Date).Year + [string](Get-Date).Month + [string](Get-Date).Day + "_Intranet_Backup.ova"
|
$backupFilename = " -o " + $backupDriveLetterMount + ":\" + [string](Get-Date).Year + [string](Get-Date).Month + [string](Get-Date).Day + "_Intranet_Backup.ova"
|
||||||
|
$vmName = "2018_intranet"
|
||||||
# setting path var to VirtualBox folder
|
# setting path var to VirtualBox folder
|
||||||
$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
|
$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
|
||||||
$regex = "[cC]\:\\Program Files\\Oracle\\VirtualBox"
|
$regex = "[cC]\:\\Program Files\\Oracle\\VirtualBox"
|
||||||
|
@ -23,31 +23,52 @@ if ( -Not ($OldPath -match $regex)){
|
||||||
Set-ItemProperty -Path "$Reg" -Name PATH -Value $virtualBoxPath
|
Set-ItemProperty -Path "$Reg" -Name PATH -Value $virtualBoxPath
|
||||||
}
|
}
|
||||||
|
|
||||||
# mounting backup path
|
# mounting backup path New-PSDrive -Name L -Root \\freenas\programas\VM_Backup\ -Persist -PSProvider FileSystem
|
||||||
New-SmbMapping -LocalPath "$backupDriveLetterMount" -RemotePath "$remoteBackupPath"
|
New-PSDrive -Name $backupDriveLetterMount -Root $remoteBackupPath -Persist -PSProvider FileSystem
|
||||||
|
|
||||||
# backing up vm
|
# stoping vm
|
||||||
vboxmanage controlvm poweroff
|
$vmanagerStopVM = "VBoxManage.exe"
|
||||||
vboxmanage export -oovf10 -o "$backupFilename"
|
$vmanagerStopVM += @(" controlvm ")
|
||||||
|
$vmanagerStopVM += @(@vmName)
|
||||||
|
$vmanagerStopVM += @(" poweroff")
|
||||||
|
Write-host "$vmanagerStopVM"
|
||||||
|
Invoke-Expression "$vmanagerStopVM"
|
||||||
|
|
||||||
|
#backing up vm
|
||||||
|
$vmanagerBackup = "VBoxManage.exe"
|
||||||
|
$vmanagerBackup += @(" export ")
|
||||||
|
$vmanagerBackup += @($vmName)
|
||||||
|
$vmanagerBackup += @(" --ovf10")
|
||||||
|
$vmanagerBackup += @([string]$backupFilename)
|
||||||
|
Write-host "$vmanagerBackup"
|
||||||
|
Invoke-Expression "$vmanagerBackup"
|
||||||
|
|
||||||
# remove old Backups
|
# remove old Backups
|
||||||
$backupFileCount = ( Get-ChildItem -Filter *.ova $remoteBackupPath | Measure-Object ).Count
|
$backupFileCount = ( Get-ChildItem -Filter *.ova $remoteBackupPath | Measure-Object ).Count
|
||||||
$limitDate = (get-date).AddDays(-12).ToString("yyyMMdd")
|
$limitDate = (get-date).AddDays(-12).ToString("yyyMMdd")
|
||||||
$backupPath = $backupDriveLetterMount + "\"
|
$backupPath = $backupDriveLetterMount + ":\"
|
||||||
|
|
||||||
if ($backupFileCount -gt 3) {
|
# start vm
|
||||||
Get-ChildItem $backupPath |
|
$vmanagerStart = "VBoxManage.exe"
|
||||||
ForEach-Object {
|
$vmanagerStart += @(" startvm ")
|
||||||
# get actual
|
$vmanagerStart += @($vmName)
|
||||||
$lasWriteTime = (Get-Content $_.LastWriteTime).ToString("yyMMdd")
|
$vmanagerStart += @(" -type headless")
|
||||||
|
Write-host "$vmanagerStart"
|
||||||
|
Invoke-Expression "$vmanagerStart"
|
||||||
|
|
||||||
# delete backup files older than 12 days
|
#if ($backupFileCount -gt 3) {
|
||||||
if ($lasWriteTime -lt limitDate ) {
|
# Get-ChildItem $backupPath |
|
||||||
$fileNameFull = Get-Content $_.FullName
|
# ForEach-Object {
|
||||||
Remove-Item –path $fileNameFull
|
# # get actual
|
||||||
}
|
# $lasWriteTime = (Get-Content $_.LastWriteTime).ToString("yyMMdd")
|
||||||
}
|
#
|
||||||
}
|
# # delete backup files older than 12 days
|
||||||
|
# if ($lasWriteTime -lt $limitDate ) {
|
||||||
|
# $fileNameFull = Get-Content $_.FullName
|
||||||
|
# Remove-Item –path $fileNameFull
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
# removing backup path
|
# removing backup path
|
||||||
Remove-SmbMapping -RemotePath "$remoteBackupPath" -Force
|
Remove-PSDrive -Name $backupDriveLetterMount
|
Loading…
Reference in a new issue