Bash Scripting
#!/bin/bash
#back up solarweb2 production on development server
# options added 11.23.2015
#written by Ken Sipe
# variables
today=$(date +%y%m%d)
c_source=/t3psolarweb202-cgi-bin
d_source=/t3psolarweb202-docs
i_source=/t3psolarweb202-docs/i-net_dev
t_source=/t3psolarweb202-tid
c_target=/usr2/cgi-bin
d_target=/usr2/docs
i_target=/usr2/docs/i-net_dev
t_target=/usr3/docs/tid
if [ $EUID -eq 0 ]
then
while getopts acdhit opt
do
case "$opt" in
h)
# help
echo "Options:"
echo "-a. Backup all webserver files (e.g. cgi-bin, docs, tid directories)"
echo "-c. Backup the cgi-bin directory only"
echo "-d. Backup the docs directory only"
echo "-i. Backup the i-net_dev directory only"
echo "-t. Backup the tid directory only"
echo "Note: You can select more than one option (e.g. -ct or -d -c)"
echo ;;
a)
#cgi-bin routine
if cd $c_source
then
echo
echo
echo "Processing cgi-bin capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $c_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_cgi-bin_t3p.$today
else
echo "Directory $c_source does not exist"
fi
#docs routine
if cd $d_source
then
echo
echo
echo "Processing docs capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $d_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_docs_t3p.$today
else
echo "Directory $d_source does not exist"
fi
#tid routine
if cd $t_source
then
echo
echo
echo "Processing tid capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $t_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_tid_t3p.$today
else
echo "Directory $t_source does not exist"
fi
#list results
echo "Directory $c_target log saved"
ls -lR $c_target > /homeb/d54712/usr-scripts-save/backup/logs/log_cgi-bin.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh
echo "Directory $d_target log saved"
ls -lR $d_target > /homeb/d54712/usr-scripts-save/backup/logs/log_docs.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh
echo "Directory $t_target log saved"
ls -lR $t_target > /homeb/d54712/usr-scripts-save/backup/logs/log_tid.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh ;;
c)
#cgi-bin routine
if cd $c_source
then
echo
echo
echo "Processing cgi-bin capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $c_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_cgi-bin_t3p.$today
else
echo "Directory $c_source does not exist"
fi
#list results
echo "Directory $c_target log saved"
ls -lR $c_target > /homeb/d54712/usr-scripts-save/backup/logs/log_cgi-bin.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh ;;
d)
#docs routine
if cd $d_source
then
echo
echo
echo "Processing docs capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $d_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_docs_t3p.$today
else
echo "Directory $d_source does not exist"
fi
#list results
echo "Directory $d_target log saved"
ls -lR $d_target > /homeb/d54712/usr-scripts-save/backup/logs/log_docs.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh ;;
i)
#i-net_dev routine
if cd $i_source
then
echo
echo
echo "Processing i-net_dev capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $i_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_i-net_dev_t3p.$today
else
echo "Directory $i_source does not exist"
fi
#list results
echo "Directory $i_target log saved"
ls -lR $i_target > /homeb/d54712/usr-scripts-save/backup/logs/log_i-net_dev.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh ;;
t)
#tid routine
if cd $t_source
then
echo
echo
echo "Processing tid capture log from production server"
/homeb/d54712/usr-scripts-save/backup/counter.sh
tar -cvf - . | (cd $t_target; tar -xvf - ) | tee /homeb/d54712/usr-scripts-save/backup/logs/log_tid_t3p.$today
else
echo "Directory $t_source does not exist"
fi
#list results
echo "Directory $t_target log saved"
ls -lR $t_target > /homeb/d54712/usr-scripts-save/backup/logs/log_tid.$today
/homeb/d54712/usr-scripts-save/backup/counter.sh ;;
esac
done
else
echo "This script must be run as root"
echo "User is $USER"
fi
No comments:
Post a Comment