Dump and Backup a MySQL Database over SSH

To do pull-backups of MySQL database tables from a server over SSH, I've found that just piping the data over SSH similar to how you would to run TAR over SSH works surprisingly well.

Depending on whether you use password with your database, or, rely on unix authentication, you will need to either use -p after the -u root or sudo.

ssh user@hostname "mysqldump --all-databases -uroot -p" > sql-backup-(date +%Y-%m-%d--%H-%M).sql

This will dump all of the databases, and pipe the resulting SQL file over SSH.

An efficient use of bandwidth? no. Feel free to pipe the result through zstd or something though if you care more about compression vs cpu cycles.

  • scripts/backups/dump_mysql_over_ssh.txt
  • Last modified: 2023-01-15 23:11
  • by Tony