MySQL备份的最佳做法 [英] Best practices for MySQL backup
问题描述
我需要在当前系统上备份MySQL数据库.我正在使用Shell脚本在cron作业中使用mysqldump
命令.
I need to backup the MySQL database on my current system. I am using the mysqldump
command in a cron job using a shell script.
以下是我的大致工作:
#!/bin/bash
fileName=$(date +%H-%M)
mysqldump -ubackup -hserver1.local.com -A database1 > /backup/$filename.sql
这大约需要1个小时才能完成,所以我的问题是这样:
This take about 1 hour to complete so my question is this:
我需要压缩数据,所以我想知道是否应该先将文件备份为纯sql然后压缩它,还是应该立即从mysqldump命令压缩它?
I need to compress the data so i would like to know if I should first back up the file as pure sql then compress it or should I compress it right away from the mysqldump command?
推荐答案
要减少中间磁盘空间的使用,您可以即时压缩:
To reduce intermediate disk space usage, you can compress on-the-fly:
mysqldump (options) | bzip2 -c > /backup/$filename.sql.bz2
这意味着您不必将整个未压缩的SQL数据写出到文件中,然后再读取回去即可对其进行压缩.
This means you won't have to write out the entire uncompressed SQL data to a file, and then read back over it to compress it.
这篇关于MySQL备份的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!