#!/bin/sh # database info db_user="user" db_pass="pass" db_host="127.0.0.1" db_name="dbname" # others vars bin_dir="/usr/bin" #the mysql bin path backup_dir="/data/backup" #the backup file directory date=`date +%F` file_name=$db_name"_"$date # todo $bin_dir/mysqldump --opt -u$db_user -p$db_pass -h$db_host $db_name > $backup_dir/$file_name".sql" cd $backup_dir tar cvzfP $file_name".tar.gz" $file_name".sql" mv $file_name".tar.gz" $db_name rm -f $backup_dir/$file_name".sql"
数据库自动备份并打成tar.gz包