Код: Выделить всё
cat /root/scripts/backup.sh
#!/bin/sh
dir="/home/backup"
# ftp functions
. /root/scripts/ftp.sh
# delete old
rm -rf $dir/`date -v-22d +%Y-%m-%d`
# new
dir="$dir/`date -v-1d +%Y-%m-%d`"
# create
mkdir -p $dir
# dump db's
mysql --execute="SHOW DATABASES;" | grep -v Database |
{
while read db
do
mysqldump --skip-extended-insert $db 2>/dev/null| gzip > $dir/$db.sql.gz
cd $dir && ftp_upload $db.sql.gz
done
}
# archive files, saturday only (too long archivation process)
if [ `date +%w` = 6 ]
then
cd $dir && tar -czf user_name.tar.gz /home/user_name
#cd $dir && ftp_upload user_name.tar.gz
fi
Код: Выделить всё
cat /root/scripts/ftp.sh
#!/bin/sh
ftp_host=bkp1.host-food.ru
ftp_user=bkp123456
ftp_pass=SuperMegaSecretPassword
# now, date is
year=`date +%Y`
month=`date +%m`
day=`date +%d`
# functions
ftp_upload(){
backup_file=$1
/usr/bin/ftp -inv -P 21 <<EOF
open $ftp_host
user $ftp_user $ftp_pass
binary
mkdir $year
cd $year
mkdir $month
cd $month
mkdir $day
cd $day
put $backup_file $new_file_name
bye
EOF
}