# 单机备份



mybackup.conf

```
username=数据库用户名
password=数据库密码
backupnode=full
（备份方式）
```

[myback.sh](http://myback.sh/)

```
#/usr/bin/env bash
BASEDIR="/home"
username=`cat ${BASEDIR}/mybackup.conf | grep "username" | awk -F '=' '{print $2}'`
password=`cat ${BASEDIR}/mybackup.conf | grep "password" | awk -F '=' '{print $2}'`
time=` date +%Y_%m_%d_%H_%M_%S `
db_name=new_retail_back
dbname=pro_wallet_back
#db=fitment_back
#dbb=wjjx_pro_wallet_back
dbyqf=yqf_back
dbdmk=duoduoke
dbgw=buhuo3
dbwz=web_duomaike
dbbhpro=buhuopro
backupdir="/mnt/data/mysql"
echo "username and password"
echo ${username}
echo ${password}
echo "begin to backup"
#mysqldump -hlocalhost -u${username} -p${password} -F --databases new_retail | gzip > $backupdir/$db_name$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases pro_wallet | gzip > $backupdir/$dbname$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases yqf | gzip > $backupdir/$dbyqf$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases duoduoke | gzip > $backupdir/$dbdmk$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases buhuo3 | gzip > $backupdir/$dbgw$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases web_duomaike | gzip > $backupdir/$dbwz$time.sql.gz
mysqldump -hlocalhost -u${username} -p${password} --databases buhuopro | gzip > $backupdir/$dbbhpro$time.sql.gz
#删除三天之前的备份
#find /home/data/mysql -name $db_name"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbname"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbyqf"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbdmk"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbgw"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbwz"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
find /mnt/data/mysql -name $dbbhpro"*.sql.gz" -type f -mtime 2 -exec rm -rf {} \; > /dev/null 2>&1
#删除一分钟之前的备份
#find $backup_dir -name $db_name"*.sql.gz" -type f -mmin +1 -exec rm -rf {} \; > /dev/null 2>&1
```
