User Tools

Site Tools


programacion:shellscripts:backup_dominios

Script para hacer backup de sitios web

Objetivo

Si bajo el directorio /vhost tenemos alojados varios dominios, con este script podemos hacer backup de los datos de cada uno de ellos independientemente, y enviar cada backup a una cuenta de correo externa (GMail en este caso) y anotar los datos y tamaño del backup en un blog Blosxom

Script

#!/bin/sh
#####################################################################
# backup_dominios.sh
# $Id: backup.sh,v 1.1.1.1 2006/01/17 18:19:44 jherrero Exp $
#
# Copyright (c) 2006, Joaquin Herrero Pintado
# Some rights reserved.
# This software is licensed under the CC-GNU GPL
# http://creativecommons.org/licenses/GPL/2.0/
#
# If you modify your copy or copies of this program or any portion of
# it, or develop a program based upon it, you may distribute the
# resulting work provided you keep this copyright notice intact and
# distribute your work under the same license.
#
#####################################################################

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin

_ROOTPATH="/vhost"
_DOMINIOS="mydomain.com otherdomain.com somedomain.org"
_EMAIL="mybackup@gmail.com"

# --------------------------------------
# Don't need to modify beyond this point

_SYS="`uname -a`"
_USER=`who am i`
_BLOGENTRY="/blogdata/backups/data.blog"

cd ${_ROOTPATH}

for _DOMINIO in $_DOMINIOS
do

   _DATE=`date +%Y%m%d-%H%M%S`
   _DOMINIO_BACKUP=${_DOMINIO}.tar.gz
   _TEMP=/tmp/back_domains_`date +%Y%m%d-%H%M%S`

   echo "Backup DOMINIO" > $_TEMP
   echo "--------------\n" >> $_TEMP
   df -h >> $_TEMP
   df -h >> $_TEMP

   echo "\n" >> $_TEMP
   echo "Disk Usage" >> $_TEMP
   echo "----------" >> $_TEMP
   du -sh ${_ROOTPATH}${_DOMINIO} >> $_TEMP
   echo "----------" >> $_TEMP
   du -sh ${_ROOTPATH}${_DOMINIO}/* >> $_TEMP

   echo "\n" >> $_TEMP
   echo "Backup Contents" >> $_TEMP
   echo "---------------" >> $_TEMP
   tar cvfz ${_DOMINIO_BACKUP} ${_DOMINIO} >> $_TEMP
   #cat ${_TEMP} | mutt -a $_DOMINIO_BACKUP -s "Backup de $_DOMINIO $_DATE" $_EMAIL

   echo "<pre>Backup $_DOMINIO el `date +%d-%m-%Y` a las `date +%H:%M:%S` : `ls -lh $_DOMINIO_BACKUP | awk '{print $5}'` </pre>"
>> $_BLOGENTRY

   rm $_DOMINIO_BACKUP
   rm $_TEMP

done
programacion/shellscripts/backup_dominios.txt · Last modified: 2007/04/02 11:20 by jherrero