Update 'all'
This commit is contained in:
parent
ec321a2699
commit
b294b4530a
1 changed files with 17 additions and 32 deletions
49
all
49
all
|
@ -10,18 +10,8 @@ $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 = " -o " + $backupDriveLetterMount + ":\" + [string](Get-Date).Year + [string](Get-Date).Month + [string](Get-Date).Day + "_Intranet_Backup.ova"
|
$backupFilename = $backupDriveLetterMount + ":\" + [string](Get-Date).Year + [string](Get-Date).Month + [string](Get-Date).Day + "_Intranet_Backup.ova"
|
||||||
$vmName = "2018_intranet"
|
$vmName = "2018_intranet"
|
||||||
# setting path var to VirtualBox folder
|
|
||||||
$Reg = "Registry::HKLM\System\CurrentControlSet\Control\Session Manager\Environment"
|
|
||||||
$regex = "[cC]\:\\Program Files\\Oracle\\VirtualBox"
|
|
||||||
$OldPath = (Get-ItemProperty -Path "$Reg" -Name PATH).Path
|
|
||||||
|
|
||||||
# check if PATH is already set
|
|
||||||
if ( -Not ($OldPath -match $regex)){
|
|
||||||
Write-host "`nSetting Path Variable to $AddedLocation"
|
|
||||||
Set-ItemProperty -Path "$Reg" -Name PATH -Value $virtualBoxPath
|
|
||||||
}
|
|
||||||
|
|
||||||
# mounting backup path New-PSDrive -Name L -Root \\freenas\programas\VM_Backup\ -Persist -PSProvider FileSystem
|
# mounting backup path New-PSDrive -Name L -Root \\freenas\programas\VM_Backup\ -Persist -PSProvider FileSystem
|
||||||
New-PSDrive -Name $backupDriveLetterMount -Root $remoteBackupPath -Persist -PSProvider FileSystem
|
New-PSDrive -Name $backupDriveLetterMount -Root $remoteBackupPath -Persist -PSProvider FileSystem
|
||||||
|
@ -29,7 +19,7 @@ New-PSDrive -Name $backupDriveLetterMount -Root $remoteBackupPath -Persist -PSPr
|
||||||
# stoping vm
|
# stoping vm
|
||||||
$vmanagerStopVM = "VBoxManage.exe"
|
$vmanagerStopVM = "VBoxManage.exe"
|
||||||
$vmanagerStopVM += @(" controlvm ")
|
$vmanagerStopVM += @(" controlvm ")
|
||||||
$vmanagerStopVM += @(@vmName)
|
$vmanagerStopVM += @($vmName)
|
||||||
$vmanagerStopVM += @(" poweroff")
|
$vmanagerStopVM += @(" poweroff")
|
||||||
Write-host "$vmanagerStopVM"
|
Write-host "$vmanagerStopVM"
|
||||||
Invoke-Expression "$vmanagerStopVM"
|
Invoke-Expression "$vmanagerStopVM"
|
||||||
|
@ -39,15 +29,11 @@ $vmanagerBackup = "VBoxManage.exe"
|
||||||
$vmanagerBackup += @(" export ")
|
$vmanagerBackup += @(" export ")
|
||||||
$vmanagerBackup += @($vmName)
|
$vmanagerBackup += @($vmName)
|
||||||
$vmanagerBackup += @(" --ovf10")
|
$vmanagerBackup += @(" --ovf10")
|
||||||
$vmanagerBackup += @([string]$backupFilename)
|
$vmanagerBackup += @(" -o ")
|
||||||
|
$vmanagerBackup += @([string]$backupFilename)
|
||||||
Write-host "$vmanagerBackup"
|
Write-host "$vmanagerBackup"
|
||||||
Invoke-Expression "$vmanagerBackup"
|
Invoke-Expression "$vmanagerBackup"
|
||||||
|
|
||||||
# remove old Backups
|
|
||||||
$backupFileCount = ( Get-ChildItem -Filter *.ova $remoteBackupPath | Measure-Object ).Count
|
|
||||||
$limitDate = (get-date).AddDays(-12).ToString("yyyMMdd")
|
|
||||||
$backupPath = $backupDriveLetterMount + ":\"
|
|
||||||
|
|
||||||
# start vm
|
# start vm
|
||||||
$vmanagerStart = "VBoxManage.exe"
|
$vmanagerStart = "VBoxManage.exe"
|
||||||
$vmanagerStart += @(" startvm ")
|
$vmanagerStart += @(" startvm ")
|
||||||
|
@ -56,19 +42,18 @@ $vmanagerStart += @(" -type headless")
|
||||||
Write-host "$vmanagerStart"
|
Write-host "$vmanagerStart"
|
||||||
Invoke-Expression "$vmanagerStart"
|
Invoke-Expression "$vmanagerStart"
|
||||||
|
|
||||||
#if ($backupFileCount -gt 3) {
|
# remove old Backups
|
||||||
# Get-ChildItem $backupPath |
|
$backupFileCount = ( Get-ChildItem -Filter *.ova $remoteBackupPath | Measure-Object ).Count
|
||||||
# ForEach-Object {
|
$backupPath = $backupDriveLetterMount + ":\"
|
||||||
# # get actual
|
|
||||||
# $lasWriteTime = (Get-Content $_.LastWriteTime).ToString("yyMMdd")
|
DO
|
||||||
#
|
{
|
||||||
# # delete backup files older than 12 days
|
$Item = Get-ChildItem -Path $remoteBackupPath -Filter *.ova | Sort CreationTime | select -First 1
|
||||||
# if ($lasWriteTime -lt $limitDate ) {
|
Write-Host "Oldest file/folder in $FolderName is $($Item.FullName)"
|
||||||
# $fileNameFull = Get-Content $_.FullName
|
Remove-Item -Path $($Item.FullName) -Force
|
||||||
# Remove-Item –path $fileNameFull
|
$backupFileCount = ( Get-ChildItem -Filter *.ova $remoteBackupPath | Measure-Object ).Count
|
||||||
# }
|
|
||||||
# }
|
} While ($backupFileCount -gt 3)
|
||||||
# }
|
|
||||||
|
|
||||||
# removing backup path
|
# removing backup path
|
||||||
Remove-PSDrive -Name $backupDriveLetterMount
|
Remove-PSDrive -Name $backupDriveLetterMount
|
||||||
|
|
Loading…
Reference in a new issue