Linux Bash Scripts

What command(s) did you use to create the “archive zip file”? I’m wondering what type of “archive” the instructions might have indicated. e.g. Were you supposed to create a tar archive and then zip the archive file? The task certainly would fail, even with a matching file name, if the validation steps unzipped the file and expected that to result in a tar archive instead of the individual files that were zipped…

1 Like

the questions were in that form
a- create a zip archive named xfusioncorp_news.zip of /var/www/html/news
b- save that file in /backup/ on app server 3
c- copy the created file to Backup server in /backup/
d- make sure that script won’t ask for password while copying the file.
for the Q-a and Q-b i set up zip unzip package, nothing mentioned about tar command, so i add the cmd below to my script:
zip -r /backup/xfusioncorp_news.zip /var/www/html/news
that command permit to create and save the zip file in /backup

for the Q-c Q-d, i run the cmds bellow:
1- ssh-keygen
2- ssh-cpy-id clint@st…
3- then i add that cmd line to my script scp -r /backup/xfusioncorp_news.zip clint@stbkp01:/backup/

the script executed with success, finnaly i checked out the output files which are located on there original path /back in stapp03 and /back in stbkp01.

hello
your line q-a should also be in your script you had to create zip file through script not separately
bot of your lines Q-a & Q-3 should have been in script

1 Like

Can i get that script new_backup.sh i m finding it hard to uderstand

1 Like

what didn’t you get precisely ???

yes, i already dit that, after reviewing, i think that i needed to copy keyid to stbkp01 from banner user not from root, therefore avoiding script asks for password while copying backup to stbkp

Like what all commands u used inside the script to take back up and all

@Akshay First of all you need to make a cmd that create a zip file and save it in / backup

So you should install zip package by running the cmd bellow:

Yum install -y zip unzip

After that, create the necessary zip file bu running

zip -r path-of-your-backp-file path-of-dir-you-would-to-take-back-of

In my case it is

Zip /backup/xfusion…zip /var/www/html/xxxx

The second cmd permit to copy that file from the web server to the backup server

Scp source destination

In this case it is

Scp /backup/xfus…zip clint@stbkp01:/backup/xfus…zip

using theses two commands will allow to you, to create your own script under /scripts/name-of-your-script.sh
any script should begin by #!/bin/bash and remenber thats cmds will run from the top first sd 3th …etc
furthermore, to make the script run without asking for password of clint user user in the second cmd, we need to generate a key and copy that key on stbkp server so try to follow these cmds :

ssh-keygen

ssh-copy-id clint@stbkp01

So in that step you will almost finish you must just run you script and check the destination dir that it contains backup files

To run script

Sh /scripts/script-name

Good luck

Hi Team,

Although,created bash script worked fine and copied zip file over backup server but still i got failed remark.

Kindly find an enclosed attached snapshot for your perusal.

Could you please check and do the needful.

because we don’t need to use tar archive, we need to use zip command.
tar cvzf creates gz2 something extention not zip.
@prashantj.jadhav26

1 Like

you must use zip command to create zip archive

thank you so much :slight_smile:

@Tej-Singh-Rana
@peterwhite
@yelmir
hi all,

as part of this task. I first ran these commands on stbkp01 server as a normal user.


on stapp02 server. I created this bash script.


this is the message I get finally.

on stapp02 the file is copied.

when I verify the backup folder in stbkp01, the file is not copied there.
image
let me know the mistake I am doing. thank you

Hello, @swaroopcs88
Read the below article and try to apply. You have to bypass that “yes/no” prompt.

@Tej-Singh-Rana
Hi Tej,
I am trying these commands will this work.
on stbkp01 server. I ran ssh-keygen


on stapp01, I created this bash script and trying to execute it.


Please check and advise. thank you

Though the zip files are getting copied to application server and backup server.
however, I am prompted for user password. so somewhere I am going wrong.


Hi @swaroopcs88,

Take a look at What is ssh-copy-id? How ssh-copy-id works? - that should help you resolve the problem…

Best,
Peter

You don’t need to add yum install zip unzip just remove that as zip binary is already available .
Just add this lines in script:

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

And do $ ssh-keygen and $ssh-copy-id clint@stbkp01 manually
Add name of the files as per task

3 Likes

@akshayyw @Tej-Singh-Rana @Inderpreet and others,

task failed with below error though i m sure about my steps.
1

Steps followed are as below:

  1. created script in stapp01
    2

  2. on stapp01
    ssh-keygen
    ssh-copy-id clint@stbkp01
    was able to login to stbkp01 from stapp01 without any password

  3. when ran script can see zip file in both stapp01 /backup folder as well as stbkp01 /backup folder.

Please assist me in getting it right.
Thanks in adavce.

Regards,
Yogendra

Hello, @yogendra
I think you have to perform this task from respective sudo user of the app server. You are in the app server 1 so should be tony not root.