<?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>DEV Community: Nikhil Kumar</title>
    <description>The latest articles on DEV Community by Nikhil Kumar (@nik0811).</description>
    <link>https://dev.to/nik0811</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%2F769611%2Ffaf883d5-1ad8-4b5d-af4a-4882dc9dc7a9.jpeg</url>
      <title>DEV Community: Nikhil Kumar</title>
      <link>https://dev.to/nik0811</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nik0811"/>
    <language>en</language>
    <item>
      <title>Replication between On-Premise MySQL and MySQL on AWS RDS</title>
      <dc:creator>Nikhil Kumar</dc:creator>
      <pubDate>Wed, 08 Dec 2021 18:36:49 +0000</pubDate>
      <link>https://dev.to/nik0811/replication-between-on-premise-mysql-and-mysql-on-aws-rds-2a1j</link>
      <guid>https://dev.to/nik0811/replication-between-on-premise-mysql-and-mysql-on-aws-rds-2a1j</guid>
      <description>&lt;p&gt;How to establish the replication between on-premise MySQL and AWS MySQL RDS?&lt;/p&gt;

&lt;p&gt;Here your on-premise MySQL will be master and MySQL running on AWS RDS will be your Slave.&lt;br&gt;
Step 1:&lt;/p&gt;

&lt;p&gt;Log in to the terminal where master MySQL is installed, for example, I have installed my MySQL server on Ubuntu.&lt;/p&gt;

&lt;p&gt;So, take the access of Ubuntu Server by SSH.&lt;br&gt;
Step 2:&lt;/p&gt;

&lt;p&gt;Now edit the file &lt;code&gt;/etc/mysql/mysql.conf.d/mysqld.cnf&lt;/code&gt; add the below line to enable bin-log.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

[mysqld]
#
# * Basic Settings
server-id = 101
auto-increment-increment = 2
auto-increment-offset = 2
#bind external address
bind-address            = 0.0.0.0

# log-bin enable
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size   = 100M
binlog_format = mixed
#binlog_do_db           = include_database_name
binlog_ignore_db        = mysql


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: Don’t copy and paste, check your conf file replace the comment if the line exists else add the line.&lt;/p&gt;

&lt;p&gt;Step 3:&lt;/p&gt;

&lt;p&gt;Restart your MySQL Server by below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo systemctl restart mysql


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 4:&lt;/p&gt;

&lt;p&gt;Create MySQL on AWS RDS.&lt;/p&gt;

&lt;p&gt;Step 5:&lt;/p&gt;

&lt;p&gt;Once MySQL get created on RDS, Copy the database of Master on-premise MySQL server to RDS MySQL Server with below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

# copy dump on rds
:~$ mysqldump --databases &amp;lt;database_name&amp;gt; \
    --single-transaction \
    --compress \
    --order-by-primary \
    -u &amp;lt;username of onprem mysql server&amp;gt; \
    -p&amp;lt;password of onprem mysql server&amp;gt; | mysql \
        --host=&amp;lt;endpoint of MySQL RDS&amp;gt; \
        --port=3306 \
        -u &amp;lt;username of RDS mysql server&amp;gt; \
        -p&amp;lt;password of RDS mysql server&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 6:&lt;/p&gt;

&lt;p&gt;On on-premise Master MySQL server create a user named “replicator” and grant the “privilege” to this user by below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; CREATE USER 'replicator'@'%' IDENTIFIED BY 'replicator';
mysql&amp;gt; GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 7:&lt;/p&gt;

&lt;p&gt;Flush the table with read lock by below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#Flush table with read lock
FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = ON;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 8:&lt;/p&gt;

&lt;p&gt;Now check the master status by below command,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwpomb6feseh1wga8f62s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwpomb6feseh1wga8f62s.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure to note “File” and “Position” value, we will be using it later on RDS MySQL side.&lt;/p&gt;

&lt;p&gt;Step 9:&lt;/p&gt;

&lt;p&gt;Make the database writable again by below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; SET GLOBAL read_only = OFF;
mysql&amp;gt; UNLOCK TABLES;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now our master on-premise MySQL configuration is completed.&lt;/p&gt;

&lt;p&gt;Step 10:&lt;/p&gt;

&lt;p&gt;Take the access of your MySQL RDS running on AWS with the help of any MySQL client package, as am using Ubuntu so I can directly install &lt;code&gt;mysql-client&lt;/code&gt; on my workstation machine which I am using, once the mentioned package get installed I need to use below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

:~$ mysql -u &amp;lt;username of RDS MySQL&amp;gt; -h &amp;lt;Endpoint of RDS MySQL&amp;gt; -p&amp;lt;password of RDS MySQL&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once you are logged in to RDS MySQL server use the below command to connect to your on-premise MySQL server,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; call mysql.rds_set_external_master ('on_prem_mysql_IP', 3306, 'replicator', 'replicator', 'file', position, 0);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Note: Don’t copy and paste the above command you need to pass the value at few of the places.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Make sure to replace the `on_prem_mysql_IP` with the IP of on-premise MySQL server.
`file` will be replaced by the value we obtain from `SHOW MASTER STATUS` above, which will be `mysql-bin.000007` as per my value.
position will be replaced by the value we again obtain from "SHOW MASTER STATUS" above, which will be 154 as per my value.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 11:&lt;/p&gt;

&lt;p&gt;It’s time to start replication by below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; call mysql.rds_start_replication;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To stop replication use the below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; call mysql.rds_stop_replication;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To skip the repl_error, if you will by mistake delete the table from slave rather deleting it from the master, use the below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

CALL mysql.rds_skip_repl_error;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To test the Status of slave use the below command,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql&amp;gt; SHOW SLAVE STATUS \G


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If there will be no error you will see,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Slave_IO_Running: Yes
Slave_SQL_Running: Yes


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>aws</category>
      <category>mysql</category>
      <category>rds</category>
    </item>
    <item>
      <title>Managing Release on GITHUB</title>
      <dc:creator>Nikhil Kumar</dc:creator>
      <pubDate>Mon, 06 Dec 2021 20:42:15 +0000</pubDate>
      <link>https://dev.to/nik0811/managing-release-on-github-19im</link>
      <guid>https://dev.to/nik0811/managing-release-on-github-19im</guid>
      <description>&lt;p&gt;I was working around a few days back, managing the release of the project with versioning and proper tags associated with it which results in writing the python code.&lt;/p&gt;

&lt;p&gt;I have written a simple python function that will call the API of GitHub and will Create/Fetch /Delete the release on GitHub.&lt;/p&gt;

&lt;p&gt;Note** You can manage the same with CURL command too but I was facing some authentication issue, so haven’t done, I haven’t tried with explicitly passing the auth token in header by -H tag, you can give a try.&lt;/p&gt;

&lt;p&gt;Have a look at the below snippet of code which can be easily integrated with Jenkins pipeline&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests
import json

user = ""             #username of github account
repo = ""             #repository_name
auth = ""             #authentication token
url = "https://api.github.com"
header = {"Authorization": "token %s" %(auth), 'Accept': 'application/vnd.github.v3.raw'}
tag_name = ""         #tag_name of release
releaseId = ""        #releaseID
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;tag_name and releaseId&lt;/code&gt; variables are only required if you want to delete a particular release, which you will rarely come across.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Fetch latest release from github
def latestRelease():
    try:
        releases = requests.get('%s/repos/%s/%s/releases/latest' %(url,user,repo), headers=header).json()
        print(releases['tag_name'], releases['id'])
    except:
        print('Release Not Found')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will be used to fetch the latest release present on GitHub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create latest release on github
def postNewrelease():
    try:
        with open('release.json') as newRelease:
            _release = json.load(newRelease)
            release_new = requests.post('%s/repos/%s/%s/releases' %(url,user,repo), json=_release, headers=header).json()
            print(release_new)
    except:
        print("error while creating new release")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet of code is used to create the release on GitHub, which contains &lt;code&gt;payload&lt;/code&gt; in JSON format.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;release.json&lt;/code&gt; will look something like below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
        "tag_name": "v1.6.0",
        "target_commitish": "master",
        "name": "v1.6.0",
        "body": "nikhil python api call release",
        "draft": false,
        "prerelease": false
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even with this payload, you can easily create prerelease of the master branch, which can be tested in the Staging environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Delete release from github by passing tag_name &amp;amp; releaseId
def deleterelease():
    try:
        releaseDeleteTag = requests.delete('%s/repos/%s/%s/git/refs/tags/%s' %(url,user,repo,tag_name), headers=header)
        releaseDeleteId = requests.delete('%s/repos/%s/%s/releases/%s' %(url,user,repo,releaseId), headers=header)
        print(releaseDeleteId,releaseDeleteTag)
    except:
        print("error wile deleting release")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above deletion method is not often required.&lt;/p&gt;

&lt;p&gt;The full script is available in the below repository.&lt;/p&gt;

&lt;p&gt;Github Link: &lt;a href="https://github.com/nik0811/github-release-api.git"&gt;https://github.com/nik0811/github-release-api.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feel free to comment below, if you will found any mistakes or required any type of modifications/enhancement. The code is fully tested so hopefully, you will not find any issues.&lt;/p&gt;

</description>
      <category>github</category>
      <category>cicd</category>
      <category>devops</category>
      <category>python</category>
    </item>
  </channel>
</rss>
