Linux Bash Scripts Kodekloud

 


Question:

Solution:

At first login to app server02

ssh [email protected] 

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 [email protected]:/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 [email protected]

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.

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 [email protected]:/backup

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

      Delete