Using UNIX pipe concept one can dump database to another server securely using ssh protocol. All you need remote execution rights for the ‘dd’ command, over SSH. This allows you to run database dumps across an encrypted channel.

Dump Postgres Database using ssh

Use pg_dump command command:
pg_dump -U USERNAME YOUR-DATABASE-NAME | ssh user@remote.server.com "dd of=/pgsql/$(date +'%d-%m-%y')"

Dump MySQL Database using ssh

Type the following command:
mysqldump -u USERnAME -p'PASSWORD' YOUR-DATABASE-NAME | ssh user@remote.server.com "dd of=/mysql/$(date +'%d-%m-%y')"


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Ron Oct 3, 2007 @ 16:50

    How do you include the Postgre password in the command line and stop the system from responding that file not found on the remote server?

  • Cory Apr 13, 2008 @ 22:18

    The MySQL backup command is not secure — anyone can view the password using `ps` on the local machine. It is preferred to use the .my.cnf file, with a [mysqldump] header.

  • melichades Aug 31, 2008 @ 17:05

    mysqldump -u USERnAME -p’PASSWORD’ YOUR-DATABASE-NAME | ssh ….

    this will lock your db-server for a very long time …

    better do a mysqlcopy … –noindexes first, then rebuild the indexes, and then go on as described.

  • DSampaolo Jun 2, 2009 @ 9:09

    Same problem as Ron. Should I touch the file first ? Seems odd… Anyway, thanks for the tips! 🙂

  • gamezat Feb 12, 2013 @ 12:25

    hello,
    how to get full backup of all database using this command ?
    thank you

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum