8

I'm tryng to set up a new Slave DB by copying another Slave DB. Normally I would simply use MySQLDump to dump the Slave and create a .sql file, then import that into the new database.

However, as our new server is a Linux (Debian 7) server (the slave I'm copying is on a Windows server), I figured I would try to pipe the dump straight into the new database. This seemed to go well, until my putty session expired and it all stopped.

I tried it again, this time using nohup .... &. But still the dump stopped as soon as my session expired.

Is there a way to make this work? My full dump command is:

nohup mysqldump -hxxx -P3306 -uxxx -pxxx --dump-slave --databases a b c d --ignore-table=a.xxx -F | mysql -h127.0.0.1 -P3306 -uxxx -pxxx &

All DB's are MySQL 5.5.

2 Answers 2

4

I think I found the problem. Apparently the nohup command ended at the | symbol, so when the session expired the second part of the command stopped with the session.

To get round this I ran:

nohup sh -c 'mysqldump -hxxx -P3306 -uxxx -pxxx --dump-slave --databases a b c d --ignore-table=a.xxx -F | mysql -h127.0.0.1 -P3306 -uxxx -pxxx' &

I checked it was running, and then EXITed the shell, and so far, it is still running.

1
  • 2
    alternatively use screen :) Jul 18, 2016 at 21:27
3

Another jazzy approach to this would be to place that command without the ampersand into a shell script. Then, execute the script, by name, in the background. For example, call the shell script transfer_mysql_data.sh in the /path/to/script folder.

Here is the content of this proposed script

SCRIPT_TO_RUN=/path/to/script/transfer_mysql_data.sh
RUNLOG=/path/to/script/transfer_mysql_data.log
date > ${RUNLOG}
mysqldump -hxxx -P3306 -uxxx -pxxx --dump-slave --databases a b c d --ignore-table=a.xxx -F | mysql -h127.0.0.1 -P3306 -uxxx -pxxx
date >> ${RUNLOG}
chmod -x ${SCRIPT_TO_RUN}

You perform the following

cd /path/to/script
chmod +x transfer_mysql_data.sh
nohup ./transfer_mysql_data.sh &

You can immediately logout and come back later.

You could then poll the run log file /path/to/script/transfer_mysql_data.log to see when the mysqldump transfer finished. It will be finished when there are two lines: start datetime and end datetime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.