<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: oderao</title>
    <description>The latest articles on Forem by oderao (@oderao).</description>
    <link>https://forem.com/oderao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F430254%2F640f6786-01a3-4dab-b1af-9fd5e2e3af47.png</url>
      <title>Forem: oderao</title>
      <link>https://forem.com/oderao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/oderao"/>
    <language>en</language>
    <item>
      <title>AWS Series:Automating File Backups to AWS S3(Windows Server) </title>
      <dc:creator>oderao</dc:creator>
      <pubDate>Sun, 12 Jul 2020 20:28:59 +0000</pubDate>
      <link>https://forem.com/oderao/automating-file-backups-to-aws-s3-windows-server-kl3</link>
      <guid>https://forem.com/oderao/automating-file-backups-to-aws-s3-windows-server-kl3</guid>
      <description>&lt;p&gt;This tutorial is for windows server but should work in principle for other operating systems&lt;/p&gt;

&lt;h3&gt;
  
  
  INSTALL AWS CLI
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;install the aws cli using the install instructions specified &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After successful installation setup default user profiles,access id and access key by running the following command&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;aws configure
AWS Access Key ID [None]: &lt;span class="nt"&gt;&amp;lt;AccessID&amp;gt;&lt;/span&gt;
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-east-1
Default output format [None]: json
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;if you dont have an ACCESS KEY, ACCESS ID follow the link below to create one &lt;a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't specify the region when running &lt;strong&gt;aws configure&lt;/strong&gt;, you'll have to specify the region  your s3 bucket is in when running s3 commands.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  S3 COMMANDS
&lt;/h3&gt;

&lt;p&gt;When using s3 commands one path argument must be specified. paths can be one of two types, &lt;em&gt;localpath&lt;/em&gt; or an &lt;em&gt;S3Uri&lt;/em&gt; The localpath represents the local directory, the S3Uri represents a URI of your S3 bucket*&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
&lt;em&gt;localpath - C://Desktop/backups&lt;/em&gt;&lt;br&gt;
&lt;em&gt;S3URI: - s3://yourbucket/yourkey&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;S3 operations generally take this pattern. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 s3command source_file/folder destinationpath&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The operations can be from a &lt;em&gt;localpath —→ S3URI&lt;/em&gt;, &lt;em&gt;S3URI —→ S3URI&lt;/em&gt; ,&lt;em&gt;S3URI —→ localpath&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Common S3 commands include &lt;code&gt;*cp,mv,rm,sync*&lt;/code&gt; etc&lt;/p&gt;

&lt;p&gt;Sample command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;aws s3 cp "C://Desktop/backups/myfile.txt" s3://your-bucket-name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This command copies the file &lt;strong&gt;&lt;em&gt;myfile.txt&lt;/em&gt;&lt;/strong&gt; to the bucket &lt;strong&gt;&lt;em&gt;your-bucket-name&lt;/em&gt;&lt;/strong&gt; no region was specified because the region was specified during &lt;code&gt;aws configure&lt;/code&gt; you can use &lt;em&gt;--region&lt;/em&gt; flag to specify the region your bucket is in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight markdown"&gt;&lt;code&gt;aws s3 sync "C://Desktop/backups/" s3://your-bucket-name 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above commands copies all contents of the folder &lt;em&gt;backups&lt;/em&gt; to the bucket  &lt;em&gt;your-bucket-name&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The sync command copies files only if &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if the size of the local file is different than the size of the s3 object,&lt;/li&gt;
&lt;li&gt;The last modified time of the local file is newer than the last modified time of the s3 object,&lt;/li&gt;
&lt;li&gt;The local file does not exist under the specified bucket and prefix&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using filters flag with s3 commands (&lt;code&gt;--exclude&lt;/code&gt;, &lt;code&gt;--include&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;--excludes removes&lt;/em&gt; specific files or folders when an s3 command is run&lt;/p&gt;

&lt;p&gt;&lt;em&gt;--includes&lt;/em&gt; adds specific files or folders when an s3 command is run&lt;/p&gt;

&lt;p&gt;the --exclude and the --include can be used multiple times in the same command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight markdown"&gt;&lt;code&gt;aws s3 sync "C://Desktop/backups/" s3://your-bucket-name --exclude "&lt;span class="ge"&gt;*" --include "*&lt;/span&gt;.jpg" --include "&lt;span class="ge"&gt;*.png" --include "*&lt;/span&gt;.txt"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The following command excludes all files in the folder &lt;em&gt;backups&lt;/em&gt;  and includes all files in the &lt;em&gt;backups&lt;/em&gt; folder that have the extensions &lt;em&gt;jpg,txt,png&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can test your settings by adding the --dryrun flag to your command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws s3 sync "C://Desktop/backups/" s3://your-bucket-name --exclude "*" --include "*.jpg" --include "*.png" --include "*.txt" --dryrun
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By default all files are included during s3 operations and the last applied filter takes precedence&lt;/p&gt;

&lt;p&gt;Read more on S3 commands &lt;a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/index.html"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Backup with Batch Files
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create batch file&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;open an empty txt file using notepad&lt;/li&gt;
&lt;li&gt;type in the s3 command you want to execute,here i want to sync my backups folders to an s3 bucket
&lt;code&gt;aws s3 sync "C://Desktop/backups/" s3://your-bucket-name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;save the txt file as a batch file(.bat)
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mOI5E1z5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/me7eukkoazya2rgnm7li.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Open windows task scheduler,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;em&gt;Create Task&lt;/em&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xhbspkzF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pnptx32az4tvcdmv70y3.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Add task name and description
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tj8vG0vv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a3dhi5958jscpv473xas.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Add trigger (&lt;em&gt;One time,Daily,Weekly,Monthly)&lt;/em&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QP3oj6F2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wch4v8wcmww4q6w3ht69.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Add &lt;em&gt;actions&lt;/em&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PHgcI2d_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5wrqgwa4bi97s88psese.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;li&gt;Save your task.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pE1-E2Am--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/feywzkdzycnathzmowkg.png" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now your backups to S3 is scheduled to run daily at 7:20pm&lt;/p&gt;

</description>
      <category>aws</category>
      <category>backup</category>
      <category>devops</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
