Linux Bash Scripts Kodekloud

 


Question:

Solution:

At first login to app server02

ssh steve@stapp02 

Then go to scripts folder and create media_backup.sh

vi media_backup.sh

Next write this commands and save it

#!/bin/bash
zip -r /backup/xfusioncorp_media.zip /var/www/html/media
scp /backup/xfusioncorp_media.zip clint@stbkp01:/backup/

Then create a keygen and copy the key to backup server so that bash script will not require any password

ssh-keygen

ssh-copy-id clint@stbkp01

Finally go to scripts folder and run the bash scripts by this command

sh  media_backup.sh

Now you can check the backup folder for the zip file on both app02 and backup server. If you find the zip file then it should be done.

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

4 comments:

  1. Hi Shawon,
    where am I supposed to run keygen commands?
    inside the script? or in application server? or backup server?
    also, do I need to run as sudo?

    ReplyDelete
    Replies
    1. you need to run keygen command in appserver. It is better to run as sudo

      Delete
  2. Hi Shawon, while running the script , i am getting permission denied error in the copy command, do i need to include sudo in the script?how should i deal with permission issues.do i need to run script as root user?Please suggest

    zip -r xfusioncorp_media.zip /var/www/html/beta
    cp xfusioncorp_media.zip /backup/

    scp -r /backup/xfusioncorp_media.zip clint@stbkp01:/backup

    ReplyDelete
    Replies
    1. Please run as a root user. sudo su command will give you root access

      Delete