Bash Website Backup Script

d
Nombre: backup-sitename.sh
Descripción: Script que permite realizar un backup de un sitio web
Más información del Script en loneshooter
#!/bin/sh
 
# Cron job runs with:
# bash /home/account/backup/backup-sitename.sh
 
SITEDIRNAME="sitename"
DBNAME="account_dbname"
DBUSER="account_name"
DBPASS="password"
BASEBCKPPATH="/home/account/backup"
DATE=$(date -I)
DESTINATIONDIR="$BASEBCKPPATH/$DATE/$SITEDIRNAME" #e.g. /home/account/backup/2012-07-29/sitename
ERRORLOG=$DESTINATIONDIR/error.log
 
# Delete all previous backups
if [ -d "$DESTINATIONDIR" ]; then
  rm -rf $DESTINATIONDIR
fi
 
# Create backup directory if it doesn't exist, e.g. /home/account/backup/2012-07-29/sitename
if [ ! -d "$DESTINATIONDIR" ]; then
  mkdir -p $DESTINATIONDIR
fi
 
# Backup site folder
tar -czf $DESTINATIONDIR/${SITEDIRNAME}_${DATE}.tgz -C /home/account/addon ./$SITEDIRNAME 2> $ERRORLOG
 
# Backup site database
mysqldump -u $DBUSER -p$DBPASS -h localhost $DBNAME| gzip -9 > $DESTINATIONDIR/${DBNAME}_${DATE}.sql.gz 2> $ERRORLOG

0 comentarios: