Linux Bash Scripts

Hi,
After verification of what the task required, I don’t know really what is wrong with my script

1 i set up zip package
2 ssh-keygen
3 ssh-cpy-id clint@stbkp01
4 create a bash script in /scripts/new_backup.sh which contains two cmds first one to zip an archive and save it in /backup the second one run a scp command to copy that zip archive in stbkp01:/backup

All my best wishes

Hi @yelmir,

In the future, it would really help others to determine what you got wrong by including the official task description in your screenshot.

With that said, your description of the task refers to “/scripts/new_backup.sh” while your screenshot contains “/scripts/news_backup.sh”, so I’d have to assume that you named your script incorrectly and that the task validation was looking for “/scripts/new_backup.sh” and didn’t find it…

Peter

1 Like

@peterwhite surely i will do it next time, about the task, according to the task failure message, the archive zip file is not present in backup server stbkp01 that what i checked it twice, and the picture attached mentioned it, also it is not a matter of wrong script name i just wrote it without “s” in the description above.
thanks

1 Like

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