Shell Script For Take Backup of Web Files on Centos/RHEL
Step 1: Create Directory For Backup Scripts and Backups
# mkdir -p /backups/web_backup /backups/scriptsStep 2: Create Backups Backup Script
# vi /backups/scripts/web_backups.sh#!/bin/bash
export path1=/backups/web_backup ### Backup Path
date1=`date +%y%m%d_%H%M%S`
/usr/bin/find /backups/web_backup/* -type d -mtime +6 -exec rm -r {} \; 2> /dev/null
mkdir $path1/$date1 ### Retention For Backups of 7 Days
cp -r /var/www/html $path1/
cd $path1/html
for i in */; do /bin/tar -zcvf "$path1/$date1/${i%/}.tar.gz" "$i"; done
if [ $? -eq 0 ] ; then
rm -r $path1/html
fi
if [ `date +%d` -eq '01' ] ; then
mv /home/som/monthly_backup_report /root/Test_192.168.72.240_Backup_Report_`date +%B_%G --date="-1 day"`
fi
/root/monitor.sh 99 | tee /root/backup_report >> /root/monthly_backup_report ### to create a backup report in /root/backup_report file
cat /root/backup_report | mail -s "backup_report of Test Server (192.168.72.240)" deb.mind009@gmail.com ### Mail the Backup Report But Need Monitoring Script for this Feature
--- save and quit (:wq) ---
Step 3: Schedule The Script on Crontab
## Then Schedule the script to Crontab for Run it As per a schedule, Here we are scheduling it Daily Basis at 12:00 AM# crontab -e
0 0 * * * /backups/scripts/web_backups.sh > /dev/null
--- save and quit (:wq) ---
# crontab -l (To see the Scheduled Crontab List)
Thanks For Visiting on My Blog, For More Tutorials Keep Visiting My Blog.