The production support team of xFusionCorp Industries is working on developing some bash scripts to automate different day to day tasks. One is to create a bash script for taking websites backup. They have a static website running on App Server 1 in Stratos Datacenter, and they need to create a bash script named official_backup.sh which should accomplish the following tasks. (Also remember to place the script under /scripts directory on App Server 1)
a. Create a zip archive named xfusioncorp_official.zip of /var/www/html/official directory.
b. Save the archive in /backup/ on App Server 1. This is a temporary storage, as backups from this location will be clean on weekly basis. Therefore, we also need to save this backup archive on Nautilus Backup Server.
c. Copy the created archive to Nautilus Backup Server server in /backup/ location.
d. Please make sure script won't ask for password while copying the archive file. Additionally, the respective server user (for example, tony in case of App Server 1) must be able to run it.
Sample Answer:
#this task should be done under the respective app server user ( not from the root user)
# login to the server( respective app server)
ssh <user>@<server>
#navigate to /scripts directory
cd /scripts
# create the official_backup.sh with the below contents
vi official_backup.sh
#!/bin/bash
zip -r /backup/xfusioncorp_official.zip /var/www/html/official
scp /backup/xfusioncorp_official.zip clint@172.16.238.16:/backup/
save the file
# now generate ssh key without password and copy to the backup server , so app server can access to backup server without password.
#generate ssh key
ssh-keygen
* press enter to give the default values
# copy the key to the backup server
ssh-copy-key-id clint@stbkp01
#now go to /scripts location and run the script
sh offcial_backup.sh
# verify
# login to backup server
ssh clint@stbkp01
# navigate to backup location
cd /backup
* you will see the xfusioncorp_official.zip inside it
Note: **The Question copied it for learning purposes.** Commands are correct but based on your question the server, user name, and other details might differ, so please do check.
No comments:
Post a Comment