0

I have a requirement to run database restore commands in parallel from shell scripts. Both the commands should run in different bash sessions in parallel.

The following are the commands I need to run.

sudo su - $user -c "db2 RESTORE DATABASE ${SDBP} FROM '/dbnfs/db2main/backups/${DB2DBP}' TAKEN AT $TIMESTAMPP ON '/data1/DB2/tablespaces/${DB2DBP}' , '/data2/DB2/tablespaces/${DB2DBP}'  DBPATH ON '/home/db2inst1' INTO ${DB2DBP} NEWLOGPATH '/data1/activelogs/${DB2DBP}' without rolling forward without prompting 2>&1"
sudo su - $user -c "db2 RESTORE DATABASE ${SDBS} FROM '/dbnfs/db2main/backups/${DB2DBS}' TAKEN AT $TIMESTAMPS ON '/data1/DB2/tablespaces/${DB2DBS}' , '/data2/DB2/tablespaces/${DB2DBS}'  DBPATH ON '/home/db2inst1' INTO ${DB2DBS} NEWLOGPATH '/data2/activelogs/${DB2DBS}' without rolling forward without prompting 2>&1"

Let me know how to achieve it.

DevOps_DS
  • 65
  • 3
  • 6
  • Add `&` at end to run process in background – Digvijay S Sep 08 '20 at 06:48
  • 3
    Does this answer your question? [How do you run multiple programs in parallel from a bash script?](https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script) – Digvijay S Sep 08 '20 at 06:49

1 Answers1

0

Since you want different bash sessions (perhaps due to long running commands), screen command might be of interest to you.

You can create new named screens (sessions), let's call it restore1 for the first command:

screen -S restore1

This will create a new screen. In this screen you can run your first command. Once command starts running, you can "detach" (ctrl+a d) from it.

Create another named screen called restore2 for SDBS:

screen -S restore2

Run the second command here, then detach from it. You can check the screens (sessions) by:

screen -list

You can reattach to any of the screens with screen -r <screen_name>, to check on the status of that command. Example:

screen -r restore1
seshadri_c
  • 6,906
  • 2
  • 10
  • 24