#!/bin/bash
user='用户'
password='密码'
dbname='数据库'
date=`date +%Y%m%d`
year=`date +%Y`
month=`date +%m`
day=`date +%d`
backup_dir=/archive/data/$year/$month/$day
filename=$dbname-${date}.sql_en.gz
# mkdir directory recursely
if [ ! -d $backup_dir ]; then
mkdir -p $backup_dir
fi
/www/server/mysql/bin/mysqldump --single-transaction
--master-data=2 -u"$user" -p"$password" "$dbname"
| gzip | gpg --always-trust -e -r 用户id -o ${backup_dir}/$filename
gpg 使用参考:
http://www.ruanyifeng.com/blog/2013/07/gpg.html
https://www.madboa.com/geek/gpg-quickstart/