<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>F5 | TekCookie</title>
	<atom:link href="https://tekcookie.com/category/f5/feed/" rel="self" type="application/rss+xml" />
	<link>https://tekcookie.com</link>
	<description>Everything about IT</description>
	<lastBuildDate>Wed, 16 Jun 2021 11:26:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/tekcookie.com/wp-content/uploads/2021/06/cropped-TekCookie-211.png?fit=32%2C17&#038;ssl=1</url>
	<title>F5 | TekCookie</title>
	<link>https://tekcookie.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">174510684</site>	<item>
		<title>Automate f5 Backup</title>
		<link>https://tekcookie.com/automate-f5-backup-with-powershell/</link>
					<comments>https://tekcookie.com/automate-f5-backup-with-powershell/#comments</comments>
		
		<dc:creator><![CDATA[jeffythampi]]></dc:creator>
		<pubDate>Thu, 27 Jun 2019 07:11:35 +0000</pubDate>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[F5]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Automate F5 Backup]]></category>
		<category><![CDATA[Backup F5 with PowerShell]]></category>
		<category><![CDATA[F5 Backup]]></category>
		<category><![CDATA[F5 backup using powershell]]></category>
		<category><![CDATA[f5 backup with powershell]]></category>
		<category><![CDATA[F5 PowerShell]]></category>
		<guid isPermaLink="false">https://adminscripter.wordpress.com/?p=94</guid>

					<description><![CDATA[Automate f5 backup using PowerShell There are many ways to take UCS backup of F5 appliance. This article explains how to automate the F5 backup using PowerShell. Below script utilize SSH to connect to F5. Once connected to F5 via ssh, tmsh is used to perform backup and linux commands for file handling. To install [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">Automate f5 backup using PowerShell</h1>



<p>There are many ways to take UCS backup of F5 appliance. This article explains how to automate the F5 backup using PowerShell. Below script utilize SSH to connect to F5.</p>



<p>Once connected to F5 via ssh, tmsh is used to perform backup and linux commands for file handling.</p>



<p>To install the module, open powershell.exe as administrator and run the below command.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">Install-Module Posh-SSH</code></pre>



<p>Posh-SSH module&#8217;s package details are available at PowerShell Gallery <a href="https://www.powershellgallery.com/packages/Posh-SSH/2.0.2" target="_blank" rel="noreferrer noopener">https://www.powershellgallery.com/packages/Posh-SSH/2.0.2</a></p>



<hr class="wp-block-separator"/>



<h1 class="wp-block-heading"><span style="text-decoration: underline;">Backup F5 UCS using PowerShell</span></h1>



<p><strong>Create password file</strong></p>



<p>Run the below code to encrypt and save the password to a file.</p>



<pre class="wp-block-code"><code lang="powershell" class="language-powershell">$passwordFilePath = "E:\Script\password.txt"
$f5LoginCred = Get-Credential admin
$f5LoginCred.password | ConvertFrom-SecureString | set-content $passwordFilePath</code></pre>



<p>Note: The secure password file created above will only work for the account which was used to create it and in the computer where the file was created. If you plan to schedule the script with a service account, then the secure password file should be generated with that account.</p>



<p>Have a look at the article <a href="https://tekcookie.com/avoid-hardcode-password-in-powershell-script/" target="_blank" rel="noreferrer noopener">https://tekcookie.com/avoid-hardcode-password-in-powershell-script/</a> to know more about password handling in PowerShell.</p>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Backup Script</strong></p>



<p>Run the below code to initiate and copy the backup.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<pre class="wp-block-code"><code lang="powershell" class="language-powershell line-numbers"># Powershell to Backup F5 configuration
#Import Posh-SSH module for handling ssh part
Import-Module Posh-SSH

### Variable Declaration ###
$F5_IP = "192.168.1.22"
$bkpDestinationPath = "\\RemoteBackupHost\f5Backup"
$passwordFilePath = "E:\Script\password.txt"
### End of Variable Declaration ###

#Below snippet reads the password while in task scheduler and then encrypts to txt file
#Comment below 2 lines after the password is exported to file

#$f5LoginCred = Get-Credential admin
#$f5LoginCred.password | ConvertFrom-SecureString | set-content $passwordFilePath 

#read password from file
$password = Get-Content $passwordFilePath | ConvertTo-SecureString 
$f5LoginCred = New-Object System.Management.Automation.PsCredential("admin",$password)

#create new Posh-SSH session with the F5 device 
$f5Session = New-SSHSession -ComputerName $F5_IP -Credential $f5LoginCred -AcceptKey

#Building Backup command
$date = (Get-Date).DateTime.Replace(":","").Replace(" ","_").Replace(",","").Replace(" ","")
$bkpCommand = "tmsh save /sys ucs backup$date.ucs"
$sshoutput = Invoke-SSHCommand -Command $bkpCommand -SSHSession $f5Session
#Execute below command if the backup is successful
if($sshoutput.Output[1] -like "*is saved." -and $sshoutput.ExitStatus -eq 0) {
    #Copy the backup file to remote location
    Get-SCPItem -ComputerName $F5_IP -Credential $f5LoginCred `
        -Path "/var/local/ucs/backup$date.ucs" -PathType File `
        -Destination $bkpDestinationPath
    
    #Find and delete backup files older than 5 days having the word "backup" in the name
    $sshDeleteCommand = "find /var/local/ucs -type f -name '*backup*' -mtime +5 -exec rm {} \;"
    $sshoutput = Invoke-SSHCommand -Command $sshDeleteCommand -SSHSession $f5Session
    
}
#Killing all the SSH session
Get-SSHSession | Remove-SSHSession</code></pre>
</div></div>



<hr class="wp-block-separator"/>



<p>Schedule this script and the f5 appliance backup is automated.</p>



<p>Note: The account used to connect to F5 should have &#8220;Advanced shell&#8221; Terminal Access and the Management port should allow SSH</p>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" fetchpriority="high" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/01/f5_managementport.jpg?resize=531%2C154&#038;ssl=1" alt="" class="wp-image-292" width="531" height="154"/><figcaption>System&nbsp;&nbsp;››&nbsp;&nbsp;Platform</figcaption></figure>



<figure class="wp-block-image size-large is-resized"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/tekcookie.com/wp-content/uploads/2020/01/f5_useraccess.jpg?resize=532%2C390&#038;ssl=1" alt="" class="wp-image-293" width="532" height="390"/><figcaption>System&nbsp;&nbsp;››&nbsp;&nbsp;Users&nbsp;:&nbsp;User List</figcaption></figure>



<p>&nbsp;</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Thank you for reading my post. Hope this is helpful to you.</p></blockquote>



<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://tekcookie.com/automate-f5-backup-with-powershell/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">94</post-id>	</item>
	</channel>
</rss>
