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 backups. They have a static website running on App Server 1 in Stratos Datacenter and they need to create a bash script named beta_backup.sh
which should do the following tasks below.
Note - remember to place the script under /scripts directory on App Server 2
Tasks:
1 - Create a zip archive named xfusioncorp_beta.zip
of the /var/www/html/beta
directory.
2 - Save the archive in /backup/
on App Server 1. This is a temporary storage as backups from this location will be cleaned on a weekly basis. Therefore, we also need to save this backup archive on Nautilus Backup Server
.
(172.16.238.16 clint H@wk3y3)
3 - Copy the created archive to Nautilus Backup Server
in the /backup/
location.
4 - Make sure the script wont ask for a password when copying the archive file. Additionally, the respective server user must be able to run it, tony in the case of App Server 1
ssh tony@172.16.238.10
sudo dnf install -y zip
vi beta_backup.sh
#!/bin/bash
echo "zip archive the static website..."
zip -r /backup/xfusioncorp_beta.zip /var/www/html/beta
echo "copying to the backup server..."
scp /backup/xfusioncorp_beta.zip clint@172.16.238.16:/backup/
# Write and then quit from vim
sudo chmod +x beta_backup.sh <-- to make the executable by all
# Generate SSH Key
ssh-keygen -t rsa
# Copy key from app server to backup server
ssh-copy-id clint@172.16.238.16 (H@wk3y3)
#Verify you can login as clint without a password
ssh clint@172.16.238.16
[clint@stbkp01 ~]$ <- Success!!!
#Return back to the appserver 01 /scripts folder and run the script:
./beta_backup.sh
zip the static content
adding: var/www/html/beta/ (stored 0%)
adding: var/www/html/beta/index.html (stored 0%)
adding: var/www/html/beta/.gitkeep (stored 0%)
copy to the backup server
xfusioncorp_beta.zip
#Verify the backup.zip is on the backup server
ssh clint@172.16.238.16
Last login: Tue Sep 2 10:49:58 2025 from 172.16.238.12
[clint@stbkp01 ~]$ cd /backup
[clint@stbkp01 backup]$ ls
xfusioncorp_beta.zip
Note - the only time you should be using sudo
here is when your changing the permissions to make the script executable.