I found this use of md5 and find the other day. I based my current backup script around it. The md5 will show if anyone modifies a file, or adds/removes a file in the web hosting root (/var/www) or in the config directory (/etc/httpd/conf.d/). If there is a change then zip each site up individually and move to a backup folder to be rsynced to other servers.
NewWWWMD5=$(find /var/www/ -type f -exec md5sum {} \; | md5sum - | awk '{print $1}') OldWWWMD5=$(cat $PARENTDIR/_var_www_*.md5) NewConfMD5=$(find /etc/httpd/conf.d/ -type f -exec md5sum {} \; | md5sum - | awk '{print $1}') OldConfMD5=$(cat $PARENTDIR/_etc_httpd_conf.d_*.md5) if [ $NewWWWMD5 = $OldWWWMD5 -a $NewConfMD5 = $OldConfMD5 ]; then echo "Neither /var/www/ nor /etc/httpd/conf.d/ have changed" else rm -rf $BACKUPDIR/*Files echo "/var/www or /etc/httpd/conf.d has changed" mkdir -p $BACKUPDIR-Files # backup /var/www for directory in /var/www/*; do if [ -d $directory ]; then bu $directory; fi done # replace previous /var/www MD5 rm -f $PARENTDIR/_var_www_*.md5 find /var/www/ -type f -exec md5sum {} \; | md5sum - | awk '{print $1}' > $PARENTDIR/_var_www_$CURRENTDAY.md5 #backup /etc/httpd/conf.d bu "/etc/httpd/conf.d" # replace previous /etc/httpd/conf.d MD5 rm -f $PARENTDIR/_etc_httpd_conf.d_*.md5 find /etc/httpd/conf.d/ -type f -exec md5sum {} \; | md5sum - | awk '{print $1}' > $PARENTDIR/_etc_httpd_conf.d_$CURRENTDAY.md5 fi
Seems to work!
Comments are closed.