千家信息网

自动备份mysql数据库脚本

发表于:2024-10-05 作者:千家信息网编辑
千家信息网最后更新 2024年10月05日,自动备份mysql数据库脚本#!/bin/sh# NCONF database backup# Script by Chen# add (and adapt) the following line t
千家信息网最后更新 2024年10月05日自动备份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 {} \;



0