微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

自动备份mysql数据库脚本

自动备份mysql数据库脚本

#!/bin/sh

# NCONF database backup

# Script by Chen

# add (and adapt) the following line to the corresponding user's crontab:

# 50 23 * * * /usr/local/nconf/ADD-ONS/backup_db.sh

# MysqL connection parameters (see config/MysqL.PHP)

DBHOST=localhost

DBPORT=3306

dbnAME=test

DBUSER=user

DBPASS=pass

# Other variables

DESTINATION=/usr/local/nconf/BACKUP/db

DATE=`date +%Y%m%d%H%M%s`

KEEPDAY=30

# run backup

MysqLdump --host=$DBHOST --port=$DBPORT -u $DBUSER --password=$DBPASS --single-transaction $dbnAME | gzip > $DESTINATION/$dbnAME-$DATE.sql.gz

# delete old backups

find $DESTINATION/ -type f -name "$dbnAME-*.sql.gz" -mtime +$KEEPDAY -exec rm {} \;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐