Can someone look at this and tell me why I'm getting an empty tar?

#!/bin/sh
####
mysqldump --opt --user=[my username] --password=[my password] | tar cvz > backup.tar.gz
####
echo | mutt -a backup.tar.gz -s \"Database Backup\" [my email]
####
rm backup.tar.gz
####

Thanks!

tar -c will not accept input from stdin, so your ... | tar <args> cannot succeed. Think about these options:
1: Do you really need tar format for a single file? Why?
2: Do this in two steps: First dump the data, then zip or tar zip the resulting file (see mysqldump --help, look for the -r flag ... unless you are on Windows, in which case redirecting onto a file is better)

commented: Thanks, after you said that I realised I had mysqldump set up wrong too. +1

1) Good question. I don't.

2) I've looked for the command to do what I want to do, and I think that's it (minus the " | tar cvz" now, of course). I just want to make a backup of my databases and send them to myself. But when I implement the command without tar, it sends me an empty sql file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.