0

I am importing a large MySQL 8 database on Ubuntu 20.04 where the import takes > 24h. Unfortunatelly my provider reconnets every 24h which leads to a stop of the import.

I am issuing this command on a ssh shell which blocks the cursor until finished:

mysql -u user -p dbname < /mnt/data/backup/DB_210703.sql 2> import.txt 2>&1 

The command should also save all output/errors to the txt file import.txt

How can this be changed so that it results in a process number and I can close the session?

4
  • My internet provider cuts the line every 24h. Commented Jul 5, 2021 at 10:22
  • There must be a command that does not need to keep the SSH tunnel open. Something like with ampersand &. Commented Jul 5, 2021 at 10:23
  • 1
    I’m voting to close this question because it's not a dba problem - this is a sysadmin issue between you and your ISP! Commented Jul 6, 2021 at 15:07
  • How is this not a dba problem if one is looking for a possibility to run a restore in the background without keeping an SSH tunnel open?! Commented Jul 13, 2021 at 14:42

1 Answer 1

1

screen

screen is like 'open me a virtual terminal that I can detach from, then re-attach to later'. You use it for long-running processes when you want to disconnect from the box.

You start a screen by entering the command screen (and press enter to clear the first message). Now you are in a new session. Run what you like. You can & it if you like, but I would recommend not as you can then re-connect later to see the output and Ctrl+C if you want to stop it.

To detach a screen, hold Ctrl then press A and D one after the other. Not Ctrl+A+D, but separate A and D presses, while holding Ctrl.

Now you are back in your old shell. You can now safely disconnect and your task will keep on running. To re-attach later, enter the command screen -r and you will get back in. Once you are finished, use exit to exit the screen session and drop back to your old shell.

Read the man pages about it, as you can open multiple screens at once, name them and reconnect to named sessions. It's quite powerful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.