I'd like a single command that:
- ssh's into my server as user foo, using the public keys I have set up
- executes a mysqldump of some database with the /etc/mysql/debian.cnf defaults-file
- to stdout, so I can pipe it locally
- while doing a sudo on the server remotely, because user foo is not allowed to read /etc/mysql/debian.cnf. foo is allowed to sudo bash but not sudo mysqldump.
This is the best I have come up:
echo 'mysqldump --defaults-file=/etc/mysql/debian.cnf dbname' | ssh -t -i keys/id_rsa -l foo example.com sudo bash -s
This ugly beast works, but produces: Pseudo-terminal will not be allocated because stdin is not a terminal.
, and I really don't like the echo. There must be a better way?