Скрипт бэкапа

#!/bin/sh
# Script name : backup.sh
# Backup database and files
DATE=`date +%Y-%m-%d_%s`
BACKUP_TO_DIR='/backup'
BACKUP_FROM_DIR='/home/www'
SERVER_NAME='server_name'
KEEP_DAYS=7
BACKUP_DIR_NAME=$SERVER_NAME.backup
SQL_USER=user
SQL_PASSWORD=password
 
cd $BACKUP_TO_DIR
if [ ! -d $BACKUP_DIR_NAME ]; then
 mkdir $BACKUP_DIR_NAME
fi
 
cd $BACKUP_FROM_DIR
/usr/bin/mysqldump -Q -q -p$SQL_PASSWORD -u$SQL_USER -hlocalhost --all-databases > sql_$DATE.sql
if [ $?=0 ]; then
 tar czf backup_$DATE.tar.gz *
 rm -f sql_$DATE.sql
 mv backup_$DATE.tar.gz $BACKUP_TO_DIR/$BACKUP_DIR_NAME
fi
 
for del in $(find $BACKUP_TO_DIR/$BACKUP_DIR_NAME -name '*.tar.gz' -mtime +$KEEP_DAYS)
do
 rm $del
done