#!/bin/bash send_backup_on_mail=no # yes or no here email_address="your.address@gmail.com" db_name="wp_blog" # database name for your site backup_dir="/kit/backup" # where to create the backup file domain_name="tech.mariusb.com" # your domain name www_dir="/var/www/$domain_name" # the directory of your sites files date=`date -d today +'%Y%m%d'` # today's date delete_date=`date -d '4 days ago' '+%Y%m%d'` # the date from 4 days ago db_user=`cat ~/.my.cnf | grep user|cut -d= -f2` # database user db_pass=`cat ~/.my.cnf | grep pass|cut -d= -f2` # database password test ! -d $backup_dir/$domain_name && mkdir $backup_dir/$domain_name mysqldump -u $db_user -p$db_pass $db_name > /$backup_dir/$domain_name/$domain_name.sql tar pczvf $backup_dir/$domain_name/$domain_name-$date.tgz $www_dir /$backup_dir/$domain_name/$domain_name.sql &> $backup_dir/$domain_name/output.txt rm -rf /$backup_dir/$domain_name/$domain_name.sql rm -rf $backup_dir/$domain_name/$domain_name-$delete_date.tgz if [ $send_backup_on_mail = "yes" ]; then mutt -s "Backup $domain_name" -a $backup_dir/$domain_name/$domain_name-$date.tgz $email_address < $backup_dir/$domain_name/output.txt elif [ $send_backup_on_mail = "no" ]; then exit fi