<?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>backup &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/backup/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sat, 31 Oct 2020 14:17:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>ESX/ESXi, AWS: Backup VMs in vCenter to AWS S3</title>
		<link>https://blog.andreev.it/2018/06/129-vcenter-aws-backup-vms-in-vcenter-to-aws-s3/</link>
					<comments>https://blog.andreev.it/2018/06/129-vcenter-aws-backup-vms-in-vcenter-to-aws-s3/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sat, 30 Jun 2018 19:16:18 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[ESX/ESXi]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[S3]]></category>
		<category><![CDATA[vCenter]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3866</guid>

					<description><![CDATA[In my home lab, I run vCenter 6.7 with several ESXi hosts and since&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In my home lab, I run vCenter 6.7 with several ESXi hosts and since I built the lab I never did any backups.<br />
Now that my VMs are not test VMs and they became fairly important, I&#8217;ve decided to take care of the backups.<br />
Initially, I was thinking of using the Veeam Free Backup, but this program can&#8217;t do any schedules in the free version. Then I decided to play with OVF Tool, but I was having multiple issues with this tool and logging with a domain account. So, finally, I used PowerCLI and AWS CLI.<br />
The idea is to create a OVA export of each VM and then upload it to an S3 bucket. The source is well commented, so you shouldn&#8217;t have any issues in the script&#8217;s logic.</p>
<pre class="brush: bash; title: ; notranslate">
######################################################################################################
# vCenter2AWS v0.1
# K.Andreev - 06/30/2018
# Description:  Creates an OVA backup of all or selected vCenter VMs 
#				and uploads them to a bucket in AWS (optional)
# Prerequisites: PowerCLI, AWS CLI (configured)
# NOTE: The VM being backed up will be shut down and powered up when the OVA file is complete
# 		If using PowerCLI 10.x execute this line once
# 			Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
######################################################################################################
# Function for logging
Function LogWrite {
   Param (&#x5B;string]$logstring)
   Add-content $LogFile -value ((Get-Date -format &quot;&#x5B;dd/MMM/yyyy:HH:mm:ss] &quot;).ToString() + $logstring)
}
######################################################################################################
########## IMPORTANT PARAMETERS. DO NOT IGNORE. MODIFY TO SUIT YOUR NEEDS. ###########################
######################################################################################################
# vCenter hostname
$VCenter = &quot;vcenter.domain.local&quot;
# vCenter username
$Username = &quot;myusername@domain.local&quot;
# vCenter password
$Password = &quot;SecretPassword&quot;
# Destination for the OVA backup files, make sure you have trailing \ at the end of this string
$Destination = &quot;D:\VMs\&quot;
# Exclude the following VMs from backups
$Exclude = @(&quot;VMware vCenter Server Appliance&quot;)
# Name of the S3 bucket (make sure it exists, lower case only, starts with s3://)
$S3Bucket = &quot;s3://vspherebackups&quot;
# Do you want to upload to S3
$Upload = $true
# Specify if the OVA file contains a time stamp 
# e.g. vmname.YYYYMMDDHHmm.ova ($true) or vmname.ova ($fasle)
$TimeStamp = $true
# Do you want the OVA files to be deleted after upload to S3
$DeleteOVA = $true
# Log file path and name
$LogFile = &quot;D:\VMs\vcenter2aws.log&quot;
######################################################################################################
################### EXPORT VMs AS OVA FILES ##########################################################
######################################################################################################
# Connect to vCenter
$Server = Connect-VIServer $VCenter -User $Username -Password $Password
LogWrite (&quot;Connected to &quot; + $Server)
# Get all VMs
$VMs = Get-VM
# Loop through each of the VMs
Foreach ($VM in $VMs) {
# Get the name of each VMs	
$Name = $VM.Name
    # Skip the backup for the VMs that are in the array variable defined above
    if ($Exclude.Contains($Name)) {
        LogWrite (&quot;Backup skipped for &quot;+ $Name)
        Continue
    }
    # Stop the VM in order to take a backup
    Stop-VM -VM $Name -Confirm:$false
    LogWrite (&quot;Stopping VM &quot; + $Name)
    # Calculates the time stamp that will become part of the name
    if ($TimeStamp) {
        $TimeStampName = Get-Date -UFormat &quot;%Y%m%d%H%M&quot;
        $TimeStampName = &quot;.&quot; + $TimeStampName
    } else
    # otherwise the time stamp will be blank
    {
        $TimeStampName = &quot;&quot;
    }
    LogWrite (&quot;Backup starts for &quot; + $Name)
    # Exports the VM as OVA file, overwrites if there is a same file at the destination
	Get-VM -Name $Name | Export-VApp -Destination ($Destination + $Name + $TimeStampName + &quot;.ova&quot;) -Format Ova -Force:$true
    LogWrite (&quot;Backup ends for &quot; + $Name)
    # Once the export completes, power up the VM
	Start-VM -VM $Name -RunAsync
    LogWrite (&quot;Starting VM &quot; + $Name)
}
# Disconnect from vCenter
Disconnect-VIServer -Server $Server -Confirm:$false
LogWrite (&quot;Disconnected from &quot; + $Server)
######################################################################################################
################################ UPLOAD TO AWS #######################################################
######################################################################################################
# Exit if upload is not needed
if (!$Upload) {
    LogWrite &quot;Upload to S3 skipped, exiting...&quot;
    exit
}
LogWrite (&quot;Upload to S3 bucket &quot; + $S3Bucket + &quot; starts&quot;)
# Use AWS CLI command to sync the destination folder and S3. 
aws s3 sync $Destination $S3Bucket
LogWrite (&quot;Upload to S3 bucket &quot; + $S3Bucket + &quot; ends&quot;)
######################################################################################################
################################ DELETE THE OVA FILES ################################################
######################################################################################################
# Exit if delete is not needed
if (!$DeleteOVA) {
    LogWrite &quot;Deleting OVA files skipped, exiting...&quot;
    exit
}
Get-ChildItem $Destination -Include *.ova -Recurse | Foreach ($_) {Remove-Item $_.Fullname}
LogWrite (&quot;Deleting OVA files from &quot; + $Destination)
LogWrite &quot;Script completed...Have a nice day!&quot;
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2018/06/129-vcenter-aws-backup-vms-in-vcenter-to-aws-s3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AWS: Restore MS SQL database to RDS</title>
		<link>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/</link>
					<comments>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sat, 05 Aug 2017 22:32:25 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[RDS]]></category>
		<category><![CDATA[restore]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=3099</guid>

					<description><![CDATA[I had to migrate a SQL 2014 database from our on-prem environment to AWS.&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>I had to migrate a SQL 2014 database from our on-prem environment to AWS. The requirement was to use RDS. So, these are the steps that I&#8217;ve taken in order to successfully migrate the database. You can also check the official AWS link <a href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html" target="_blank" rel="noopener noreferrer">here</a>. </p>
<p>First, take a backup of the existing database in <strong>BAK </strong>format. In my case for the purpose of this blog, I&#8217;ve backed up my vCenter database called <strong>VCDB </strong>in a file called <strong>VCDB.BAK</strong>. Once you have the file, create a S3 bucket in AWS with the default settings and upload the BAK file there. In my case the S3 bucket was named <strong>restoremybackup</strong>.<br />
Next, make sure you have access to a Windows server with SQL Management Studio installed, either in AWS or on-prem, but this server will need to talk to the RDS database over port 1433 TCP. I built a server in AWS and installed the SQL Management Studio, which is a free download. Make sure that you have a security group in place that allows port 1433. We will use this security group to assign it to the RDS instance. I&#8217;ve created a new security group called <strong>sgAllowSQLAccess</strong>. For the source, type the IP of the server with SQL Management Studio or the security group itself. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png" alt="" width="681" height="375" class="aligncenter size-full wp-image-7650" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-01.png 681w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-01-300x165.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-01-585x322.png 585w" sizes="(max-width: 681px) 100vw, 681px" /></a><br />
Then, go to RDS and create an <strong>Option Group</strong>. Name the <strong>Option Group</strong>, in my case it&#8217;s <strong>ogSQL2014Restore</strong>, choose the engine and the version. I am using <strong>sqlserver-se</strong> which is <strong>SQL Standard Edition</strong> and the version is <strong>12.00</strong> which is <strong>MS SQL 2014</strong>. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png" alt="" width="684" height="282" class="aligncenter size-full wp-image-7651" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-02.png 684w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-02-300x124.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-02-585x241.png 585w" sizes="(max-width: 684px) 100vw, 684px" /></a><br />
Once created, select your <strong>Option Group</strong> and click on <strong>Add Option</strong>. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png" alt="" width="672" height="288" class="aligncenter size-full wp-image-7652" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-03.png 672w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-03-300x129.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-03-585x251.png 585w" sizes="(max-width: 672px) 100vw, 672px" /></a><br />
Choose <strong>SQLSERVER_BACKUP_RESTORE</strong>, then click on <strong>Create a New Role</strong>. For the role, use a name, in my case it&#8217;s <strong>iamRestoreSQLBackup</strong>. Then type the name of the S3 bucket that you just created and make sure that you select <strong>Apply Immediately &#8211; yes</strong>.<br />
Then click on <strong>Add Option</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png" alt="" width="636" height="316" class="aligncenter size-full wp-image-7653" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-04.png 636w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-04-300x149.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-04-585x291.png 585w" sizes="(max-width: 636px) 100vw, 636px" /></a><br />
Now, it&#8217;s time to create the RDS database. Launch a new RDS instance and use the parameters that suit your needs. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png" alt="" width="647" height="566" class="aligncenter size-full wp-image-7654" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-05.png 647w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-05-300x262.png 300w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-05-585x512.png 585w" sizes="(max-width: 647px) 100vw, 647px" /></a><br />
For the next set of options, choose your preferred settings, but make sure that you assign the <strong>Security Group</strong> that we just created and the <strong>Option Group</strong> that we also created. In my case it looks like this. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png" alt="" width="571" height="706" class="aligncenter size-full wp-image-7655" srcset="https://blog.andreev.it/wp-content/uploads/2017/08/P087-06.png 571w, https://blog.andreev.it/wp-content/uploads/2017/08/P087-06-243x300.png 243w" sizes="(max-width: 571px) 100vw, 571px" /></a><br />
Once the RDS it&#8217;s in available state, try to telnet to port 1433 to the RDS endpoint from the Windows server where you have the SQL Management Studio installed. If everything is OK, you are ready to restore the database. In SQL Management Studio, select a <strong>New Query</strong> and type the following. </p>
<pre class="brush: sql; title: ; notranslate">
exec msdb.dbo.rds_restore_database 
        @restore_db_name='database_name', 
        @s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';
</pre>
<p>Replace <strong>&#8216;database_name&#8217;</strong> and <strong>&#8216;bucket_name/file_name_and_extenstion&#8217;</strong> with your values. In my case, they were <strong>VCDB </strong>and <strong>restoremybackup/VCDB.BAK</strong>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2017/08/109-aws-restore-ms-sql-database-rds/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
