Total Pageviews

Sunday, December 29, 2024

How to Push file from local server to Github Repository

Steps: 

Create directory myplays 

[root@srv1 ~]# mkdir myplays 

Navigate to this directory 

[root@srv1 ~]# cd myplays

[root@srv1 myplays]# 

At this moment we don’t have any file under this directory. 

[root@srv1 myplays]# ll

total 0 

[root@srv1 myplays]#git init 

[root@srv1 myplays]#ls -lrta 

Let’s configure one user whore create the files in the repository. 

[root@srv1 myplays]#git config --global user.name "Myionic1409"

[root@srv1 myplays]#git config --global user.email "oracleforensics4u@gmail.com"

 [root@srv1 myplays]#git config --global -l 

Let’s create one playbook under below directory. 

[root@srv1 myplays]#pwd

[root@srv1 myplays]#/root/myplays 

[root@srv1 myplays]# cat first_pb.yml

---

- name: First Basic PB

  hosts: localhost 

  tasks:

  - name: Test Connectivity

    ping: 

Check the status using below command. It will show nothing added to commit. 

[root@srv1 myplays]# git status

# On branch master

#

# Initial commit

#

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#     first_pb.yml

nothing added to commit but untracked files present (use "git add" to track) 

Let’s add all these file present in this directory. 

[root@srv1 myplays]# git add -A 

Or:

We can also use below command to add specific file. 

[root@srv1 myplays]# git add first_pb.yml 

Check the status now 

[root@srv1 myplays]# git status

# On branch master

#

# Initial commit

#

# Changes to be committed:

#   (use "git rm --cached <file>..." to unstage)

#

#             new file:   first_pb.yml

#

 Take the snapshot using below commit command: 

[root@srv1 myplays]# git commit -m "firstplaybook-30Dec24-ver1" 

Create the links (where you want to copy the file): 

[root@srv1 myplays]# git remote add origin https://github.com/myionic1409/ansiblerepo.git 

Push the file: 

[root@srv1 myplays]# git push -u origin main

Username for 'https://github.com': oracleforensics4u@gmail.com

Password for 'https://oracleforensics4u@gmail.com@github.com': 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xxx

Counting objects: 7, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (5/5), done.

Writing objects: 100% (7/7), 719 bytes | 0 bytes/s, done.

Total 7 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1), done.

To https://github.com/myionic1409/ansiblerepo.git

 * [new branch]      main -> main

Branch main set up to track remote branch main from origin. 

To Generate the Token (Password) from github account.



 

Saturday, December 7, 2024

Setup log-based replication in Postgres database (Standby Database)

 Initial setup on Master server:

1)      Create ssh key on master and copy it to standby

Syntax : ssh-keygen

           Copy the ssh key to standby server

             Syntax : ssh-copy-id  postgres@ipadress

              e.g. ssh-copy-id postgres@192.168.1.125

2)      Test copying a file from master to standby without entering password.

3)      Shutdown Master database

4)      Navigate to location /var/lib/pgsql/15/data and modify the content of postgres.conf file and edit parameters archive_on, archive_command and archive_timeout.

Archive_command: rsync -a %p postgres@ipaddress:/location of archive folder

cd  /var/lib/pgsql/15/data

vi postgres.conf

Below the specimen of postgres.conf file and we have to make the changes as highlighted.

 

File andarchive_mode = on      # enables archiving; off, on, or always

                                # (change requires restart)

#archive_library = ''           # library to use to archive a logfile segment

                                # (empty string indicates archive_command should

                                # be used)

archive_command = 'rsync -a %p postgres@192.168.1.125:/var/lib/pgsql/15/archive/%f'     # command to use to archive a logfile segment

                                # placeholders: %p = path of file to archive

                                #               %f = file name only

                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'

archive_timeout = 60            # force a logfile segment switch after this

                                # number of seconds; 0 disables

 

Initial Setup Standby Database:

1)      Create a archive directory on standby which is accessible by Master user.

cd /var/lib/pgsql/15

mkdir archive

 

2)      Login as root and Shutdown postgresql on standby

-bash-4.2$ su -

Password:**********

[root@srv2 ~]# systemctl stop postgresql-15

 

3)      Delete all the contents of /Data directory

cd /var/lib/pgsql/15/data

rm –rf *

Steps:

1)      Startup postgresql on Master database

2)      Connect to the database using psql shell

3)      Issue connect pg_start_backup

Syntax : select pg_backup_start(‘dbrep’);

 

postgres=# select pg_backup_start('dbrep');

 pg_backup_start

-----------------

 0/3000028

(1 row)

4)      Copy Data directory for master to standby.

Syntax : rsync -avz /var/lib/pgsql/15/data/* postgres@192.168.1.125:/var/lib/pgsql/15/data/

5)      End backup on master.

Syntax : select pg_backup_stop();

6)      Comment out archive_on, archive_command and archive_timeout parameters in postgresql.conf in standby server.

7)      Setup recovery command in postgresql.conf

Restore_command = ‘cp /var/lib/pgsql/12/archive/%f %p’

 

SPECIMEN of postgresql.conf in standby. Commentout highlighted in red and add the parameter marked in green.

 

# - Archiving -

 

#archive_mode = on              # enables archiving; off, on, or always

                                # (change requires restart)

#archive_library = ''           # library to use to archive a logfile segment

                                # (empty string indicates archive_command should

                                # be used)

#archive_command = 'rsync -a %p postgres@192.168.1.125:/var/lib/pgsql/15/archive/%f'     # command to use to archive a logfile segment

                                # placeholders: %p = path of file to archive

                                #               %f = file name only

                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'

#archive_timeout = 60           # force a logfile segment switch after this

                                # number of seconds; 0 disables

 

# - Archive Recovery -

 

# These are only used in recovery mode.

 

restore_command = 'cp /var/lib/pgsql/15/archive/%f %p'  # command to use to restore an archived logfile segment

                                # placeholders: %p = path of file to restore

                                #               %f = file name only

8)      Create a standby.signal file in data directory.

touch standby.signal

 

9)      Start postgres on standby server

10)   Check the log files whether the postgres has entered standby mode and accepting read only connections.

cd /var/lib/pgsql/15/data/log

-bash-4.2$ ls -lrth

total 224K

-rw-------. 1 postgres postgres 5.1K Aug 17 04:36 postgresql-Sat.log

-rw-------. 1 postgres postgres 213K Dec  8 02:49 postgresql-Sun.log

      Test Standby Database:

1)      Try to create table and insert few records on master and check whether they are populated

On the standby .

2 )  try to create a table on standby or delete any records on standby

 

Failover:

1)      Shutdown postgresql on master and check whether it affects standby

2)      Promote your standby database to primary. Use any of the 3 methods

Pg_ctl promote -D /var/lib/pgsql/15/data

3)      Check signal.standy exist or not.

4)      Bring up the postgresql old master server and try to create a table there and check whether

Its replicated.