MySQL rsync方式备份

#! /bin/bash

exec 1>/var/log/mysqlbak.log 2>&1
data_source=/home/mysql/
backup_dir=/mnt/mysqlbak
remote_dir=1.2.3.4:/data/mysqlbak
n=`date +%d`
w=`date +%w`
echo backup of mysql begins at `date`
/etc/init.d/mysqld stop
p=/var/run/mysqld/mysqld.pid
        while ps -p $p >/dev/null;
        do
            sleep 1 && echo -n .
       done
sync;sync;sync;sleep 2;
rsync -aru --delete  $data_source/*  $backup_dir/mysql_$w/
/etc/init.d/mysqld start
echo backup of mysql  finished at `date`
rsync -aru --delete $backup_dir/mysql_$w/*  $remote_dir/mysql_$n/
echo remote backup of mysql  finished at `date`

添加新评论 »