Ubuntu automysqlbackup 配置为使用 gzip 在一个文件夹中拥有单独的数据库

Ubuntu automysqlbackup 配置为使用 gzip 在一个文件夹中拥有单独的数据库

我在 Ubuntu 10.04 上运行了 automysqlbackup,它运行良好。
我目前让它对所有数据库执行每日备份,但我想调整配置以执行以下操作:

将所有数据库的每日备份保存到一个文件夹中,但作为单独的 .sql 文件,然后将该文件夹作为 gzip 并带有执行备份的时间戳。

我想知道是否有其他人成功做到了这一点,如果是的话,我该如何配置它?

谢谢!

答案1

明白了 - 我刚刚把它放到了 cron 中。根据以下内容做了一些修改Jason Tan 的回答

#!/bin/sh
# Find out what databases are in mysql and back them up
# Delete old backups
STARTTIME=` date +%Y%m%d-%H%M `

#BACKUP_DIR="/var/backup/db/data"
BACKUP_DIR="/var/backup/db/data"
LOGFILE="/var/backup/db/data.log"
USER="root"
PASSWD="<password>"
KEEP="20"

(
echo
echo " ---MySQL backups start ${STARTTIME} ---"
#delete any backup written more than ${KEEP} days ago
echo "Removing files over ${KEEP} days old from ${BACKUP_DIR}:"
/usr/bin/find  ${BACKUP_DIR} -mindepth 1 -mtime +${KEEP} -print -delete
echo
echo "Performing today's dumps"
#find each database running in this instance of mysl
for DB in ` echo "show databases;"|mysql -u${USER} -p${PASSWD} mysql |awk " NR>1 {print         
$1} " `
do
    #generate a backup file name based on the data base name
    BACKUP_FILE="${BACKUP_DIR}/${DB}-${STARTTIME}.sql"
    echo "Processing database ${DB} into file ${BACKUP_FILE}"
    # dump the database data/schema into the backup file
    mysqldump -u${USER} -p${PASSWD} ${DB} > ${BACKUP_FILE}
    #gzip ${BACKUP_FILE}
done

ENDTIME=` date +%Y%m%d-%H%M `
echo
echo " ---MySQL backups complete ${ENDTIME} ---"
echo
) >>  ${LOGFILE} 2>&1

ENDTIME2=` date +%Y%m%d-%H%M `
(
#copy backup directory to a new backup directory with end time  

tar -zcvf ${BACKUP_DIR}-${ENDTIME2}.tar.gz ${BACKUP_DIR}
)

相关内容