the scripts assumes the following :
1) websites are located at websites/daomin.com
2) this script can delete add edit dail - monthly -weekly backups
3) there is cron script in /etc/cron.daily/website_backup wit he following vaiables subsitution ar the geginning od the script !!
dailly=`date +%H`
weekly=`date +%a`
monthly=`date +%d`
mark=`date +%C%a%B%Y`
weekly=`date +%a`
monthly=`date +%d`
mark=`date +%C%a%B%Y`
#!/bin/bash
clear
daily_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
weekly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
monthly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $monthly = "31" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e " Today is not the 31st of the months "
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
delete_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -n "$test_website" ]; then
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
else
echo -e "the scritp for $d does not exist"
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
read -p "read enter your domain name: " d
read -p "Back up to be done [ delete / daily / weekly / monthly ]: " p
read -p " Enter folder to be backed up " f
case $p in
delete ) delete_backup
;;
daily ) daily_backup
;;
weekly ) weekly_backup
;;
monthly ) monthly_backup
;;
* ) echo -e " Please enter daily , weekly or monthly "
esac
--
clear
daily_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
weekly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $weekly = "sun" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e "######### today is not sunday ##########"
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
monthly_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -z "$test_website" ]; then
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ $monthly = "31" ]; then
tar cvf /websites/$d/backup/$d.\$mark.tar /websites/$d
else
echo -e " Today is not the 31st of the months "
fi
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
else
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
cat >> $website_backup << _eof_
##################${d}2631#######################
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
tar cvf /websites/$d/backup/$d.$mark.tar /websites/$d
else
echo -e '########## the back up dir does not exist #############'
fi
else
echo -e '########## the folder does not exist #############'
fi
else
echo -e '######### the domain does not exsit #########'
fi
#####################${d}2631########################
_eof_
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
delete_backup ()
{
test_website=`sed -n /"\<${d}2631\>"/,/"\<${d}2631\>"/p /etc/cron.daily/website_backup`
website_backup='/etc/cron.daily/website_backup'
if [ -d /websites/$d ]; then
if [ -d /websites/$d/$f ]; then
if [ -d /websites/$d/backup ]; then
if [ -n "$test_website" ]; then
sed -i /"\<${d}2631\>"/,/"\<${d}2631\>"/D /etc/cron.daily/website_backup
else
echo -e "the scritp for $d does not exist"
fi
else
echo -e "########## the backup dir does not exist #############"
fi
else
echo -e "########## the folder $web does not exist #############"
fi
else
echo -e "######### the domain $d does not exsit #########"
fi
}
read -p "read enter your domain name: " d
read -p "Back up to be done [ delete / daily / weekly / monthly ]: " p
read -p " Enter folder to be backed up " f
case $p in
delete ) delete_backup
;;
daily ) daily_backup
;;
weekly ) weekly_backup
;;
monthly ) monthly_backup
;;
* ) echo -e " Please enter daily , weekly or monthly "
esac
--
No comments:
Post a Comment