Hi i need to backup all my mysql database using ssh. How i can do it. I have 68 databases and i know how i can do it one by one. I need some solution to do it automatic
Who is Participating?
InsoftserviceConnect With a Mentor Commented:
Why can't you use sqlyog or some gui tool.
I am using sqlyog as it has feature of schedule backup and making zip of it.
so, file size issue gets automatically resolved
omarfaridConnect With a Mentor Commented:
you can do this in two ways:

1- set trust (no passwords to login remotely, it will be based on keys generated and exchanged between the systems) between your account on your system and the account on the remote system.

please see


Then you can use

ssh username@hostname1 "command"

The above can be automated with a loop to go through different remote servers

2- If you don't want to set trust between systems, then you can use expect to automate login (response to password prompts etc.

Please see link below

xtermConnect With a Mentor Commented:
I've put a little script below that you can modify - it will do an incremental backup over rsync so it will only copy what has changed since last time you backed up.

To run it each night at 1AM, put the following in /etc/crontab:
0 1 * * * root /path/to/mybackup.sh

Currently, it will prompt you for your password each time, so before you cron it, you will need to set up passwordless ssh.  This is pretty simple.  Go into the .ssh folder in the home directory of the user who will be doing the backup (probably root, but perhaps mysql) and find the file called id_rsa.pub  Now copy that file over to the backup server, into the home directory of the user that you're logging in as.  Find the file .ssh/authorized_keys and append your public key to the end of that file with this command:

cat id_rsa.pub >> authorized_keys

The next time you ssh in, it should no longer prompt you for a password.  BTW, if the file authorized_keys did not exist previously, you can still use the command above to create it.  But you will need to do this command to give it the right permissions:

chmod 600 authorized_keys

Let us know if you get stuck, and we'll help you through it!


# mybackup.sh (sample name for this script)

DBDIRS="/var/lib/mysql /other/mysql/directory"

for DBDIR in `echo $DBDIRS`;
        rsync -az $KEEPARGS $DBDIR -e 'ssh' myusername@otherhostname:/backups/databases

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.