我像这样通过 ssh 进行备份:
mysqldump -u dbuser -pXXXXXXXX dbname | ssh -i ~/.ssh/id_rsa_backup [email protected] 'cat > /var/backups/services/my_service/db/$(date +"%Y-%m-%d").sql'
如何发送 gzip 数据以节省带宽和磁盘空间?
答案1
将其添加到 ~/.ssh/config ssh 将即时进行 gzip 压缩:)
http://linux.die.net/man/5/ssh_config了解更详细的选项
Host *
Compression yes
# from 1 (fast) to 9 (slow, best). The default level is 6
# CompressionLevel 9
# ServerAliveInterval 15
# ServerAliveCountMax 3
# KeepAlive yes
Host bak-serv
Hostname my.server.com
IdentityFile ~/.ssh/id_rsa_backup
User backup
# Port 22
使用您的命令,您最终会得到一个 sql.gz,而不是纯的 sql 文本文件。
mysqldump -u dbuser -pXXXXXXXX dbname \
| gzip | cat | ssh -i ~/.ssh/id_rsa_backup [email protected] \
'cat > /var/backups/services/my_service/db/$(date +"%Y-%m-%d").sql.gz'
变成
mysqldump -u dbuser -pXXXXXXXX dbname \
| ssh bak-serv \
| gzip -c > /var/backups/services/my_service/db/$(date +"%Y-%m-%d").sql.gz