4

i have this script and it works but the output isn't zipped so it's huge. I want to save it zipped but i don't understand shell script and i don't want to mess it up. Can you help me zip it like so: ".sql.zip", please?

/usr/bin/mysqldump -h $mysql_host -u $mysql_username -p$mysql_password $mysql_database > $backup_path/$today/$mysql_database-`date +%H%M`.sql

Any help appreciated.

3 Answers3

24

I think you can just do this.

/usr/bin/mysqldump -h $mysql_host -u $mysql_username -p$mysql_password $mysql_database | gzip -9 -c > $backup_path/$today/$mysql_database-`date +%H%M`.sql.gz
7

Just 'pipe the output' to gzip

The command would become this:

 /usr/bin/mysqldump -h $mysql_host -u $mysql_username -p$mysql_password $mysql_database | gzip > $backup_path/$today/$mysql_database-`date +%H%M`.sql.gz
Bert
  • 3,283
6

You can pipe it though gzip (or bzip2, pbzip2, xz, etc...) like so:

/usr/bin/mysqldump -h $mysql_host -u $mysql_username -p$mysql_password $mysql_database | gzip -c > $backup_path/$today/$mysql_database-`date +%H%M`.sql.gz

zip isn't the optimal tool for this job because it stores data as files in an archive (like tar + gzip), where the other tools just compress data.

mysqldump (mysqldump -C) also supports compressed communication which could perhaps make things transfer faster over the network.