Just to jot it down lest I forget:
Tar’ing the local directory and streaming the tarball straight to gzip:
tar cvf - . | gzip > target.tar.gz
MySQLdump’ing directly to gzip:
mysqldump --opt --single-transaction -h HOST -u USER -pPASS DATABASENAME| gzip > OUTPUT.sql.gz
Using --single-transaction above to avoid locking restrictions on the tables, and it’s more efficient than --lock-tables=false. In large database situations, though, just replicate…
To add a timestamp:
NOW="$(date +"%Y-%m-%d")"
and use $NOW as part of the filename
for example as single line (or just #!/bin/bash) it
NOW="$(date +"%Y-%m-%d")" && tar cvf - . | gzip > target_$NOW.tar.gz)
But you knew that already…
Tags: backup, bash, compression, gzip, locking, mysql, mysqldump, on the fly, pipe, tar
This links well to another way of tar’ing a directory and all subdirectories and the key-less SSH login with key exchange for an SCP-based all-in-one solution.