Доброго времени суток. Мой скрипт:
#!/bin/bash
TGT_dir="/home/user/backup/"
backup() {
Name=$1
Source_dir=$2
BP_name=$Name."$(date +'%Y_%b_%d%R')".tar.gz
echo "====================================================="
echo "$(date +'%d-%b-%Y %R')"
echo "Задание \"$Name\" запущено..."
tar -czf $TGT_dir$BP_name $Source_dir
echo "Finish backup ${Source_dir}"
srv_dir="${srv_dir}${syst_dir}/$BP_name"
}
backup site1 /var/www/html/drupal/
backup site2 /var/www/html/wp/
backup site3 /var/www/html/opencart/
backup db_site1 /var/lib/mysql/drupal/
backup db_site2 /var/lib/mysql/wordpress/
backup db_site3 /var/lib/mysql/opencart/
date
syst_dir=/home/user/backup/
srv_name=user
srv_ip=127.0.0.1
srv_user=backup
srv_dir="/home/user/backup/{$BP_name,$BP_name1,$BP_name2,$db_name,$db_name1,$db_name2}"
echo "Start backup ${srv_name}"
mkdir -p ${syst_dir}${srv_name}/
cd ${syst_dir}${srv_name}/
rm $(ls -t | tail -n +7) -rf
rsync -a --delete-after $srv_name@$srv_ip:$srv_dir ${syst_dir}${srv_name}
date
echo "Finish backup ${srv_name}"