In Bash Write two scripts, \'backup.sh\' and \'restore.sh\' which do the followi
ID: 3673608 • Letter: I
Question
In Bash
Write two scripts, 'backup.sh' and 'restore.sh' which do the following:
backup.sh
accepts a list of arguments which indicate the name o the output file and a list of files that should be backed up.
Will take all of the files provided oher than the first and create a tar-ball(a tarred, gzipped file) with the name provided in the first argument.
restore.sh
Accepts a single filename of a tar-ball created by the script above and restores the files from the backup
This should overwrite any existing files
Explanation / Answer
Restore and ufsrestore command restores files backed up with dump command.
Syntax is
restore options arguments files-dirs
Options
-r will read and restore the entire tape.
-x will extract all files and directory listed and restore in current directory.
-t will type the names of the listed files as they appear on terminal.
-f must be followed by a device name, otherwise default device is assumed.
-i will launch interactive mode to restore the files you want to pick.
#!/bin/bash
# What to backup.
backup_files="/home /var/spool/mail /etc /root /boot /opt"
# Where to backup to.
dest="/mnt/backup"
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh $dest
Execution:
------------
chmod u+x backup.sh
sudo ./backup.sh