🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
mybackup.conf ``` username=数据库用户名 password=数据库密码 backupnode=full (备份方式) ``` 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 ``` 异地备份 remote_backup.sh ``` #!bin/bash #The author : RoES #date:2019/6/3 #Used for:mysql remote_backup #用于数据库异地备份 basefile=/mnt/data/mysql/ ip=112.74.53.175 date echo "becoming remote_backup" echo "---start backup-------" rsync -avz /mnt/data/mysql/* root@112.74.53.175:/home/data/mysql/ echo "backup complete" exit $? ```