I have two shell scripts to write that will be executed nightly via cron schedule.
On my production server:
mysqldump -ufoo -pbar --opt --routines db > ~/sqldump/{$todays_date}.sqlln -s ~/sqldump/{$todays_date}.sql latest.sql
On my development server:
scp foo@domain.tld:~/sqldump/latest.sql ~/sqldumpmysql -ufoo -pbar db < latest.sql
I have two questions:
- In the production server job, how do i get
$todays_dateto fill in the date? e.g., “2010-07-21” - How do I make step two wait for step 1 to finish in each job?
To get today’s date, use
date +%F:To read more about the various options you can use with date’s
+formatting, check out the date man page.As for waiting, I assume you mean you don’t want to run the command on your dev server until the commands on your prod server are done. The best idea would be to have the dev server start the command using ssh (i.e.
ssh user@host "mysqldump ... > ... && ln -s ...).If you don’t want to do that, the best I can think of is to use a temp file so that the dump file creation is atomic:
Then if you have your dev server request’s the dump from today’s date, then you can loop until the scp succeeds: