HTTP (Websites) Backup script in linux

What would happen if you woke up tomorrow and your web host had accidentally deleted your website? It happened to me. And, you guessed it: I didn't have a backup. That won't ever happen to me again and I'm here to help you get prepared too.

Rsync is a piece of software that allows you to copy files from one server to another. It's clever because it will only transfer files (and even just parts of files) that have changed, saving you time and bandwidth.
Setting rsync up is not a straight-forward process, but if you have a second Linux server under your command, this offers a great way to backup your site incrementally


[root@phpMyfaq ~]# cat /root/Scripts/HTTP_Backup
#!/bin/sh
# System  backup script
# Full backup day - Sun (rest of the day do incremental backup)
# ---------------------------------------------------------------------
### System Setup ###
DIRS="/var/www/html /home /etc/httpd/"
BACKUP="/root/Backup/HTML/"
NOW=$(date +"%d_%m_%y")

#### MAIL STUFF ####
EMAILID="support@example.com"

##### START BACKUP FOR FILE SYSTEM ######
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :

  FILE="FULL-$NOW.tar.gz"
  tar -zcpf $BACKUP/$FILE $DIRS

##### DUMPING BACKUP USING RSYNC #####
  rsync -avz $BACKUP/* 172.20.1.30:/backup/10.125.1.240/html/

##### FIND OUT IF RSYNC BACKUP FAILED OR not ######
if [ "$?" == "0" ]; then
 mv $BACKUP/* /root/LASTBKP/HTML/
 else
 T=/tmp/backup.fail
 echo "Date: $(date)" >$T
 echo "Hostname: $(hostname)" >>$T
 echo "HTML Backup Failed" >>$T
 mail -s "WEB Backup Failed $Hostname" "$EMAILID" <$T
 rm -f $T
fi



Comments

Popular posts from this blog

Defining Audit Rules

AIX Install packages, upgrade, patching commands

Oracle Database Quick Installation steps 11g Release 2 for Linux x86-64