0

I'm using ubuntu 16.04 with nginx installed, currently i run daily backup using cron like this:

#crontab -u root -e

0 2 * * * mysqldump -u username -p"password" production | gzip -c > production.gz 

this will backup my database everydate at 2am, the problem here is i need to backup database based on day name, so the backup database name will be suited based on dayname, for example the file name will look like this:

production_monday.gz
production_tuesday.gz
production_wednesday.gz
production_thursday.gz
production_friday.gz
production_saturday.gz
production_sunday.gz

how can i set the cron to produce the file like above ? cron schedule will auto rewrite the file based on the day name

blue
  • 1,695
  • 3
  • 10
  • 17
  • 1
    Possible duplicate of [Linux shell script for database backup](https://stackoverflow.com/questions/19664893/linux-shell-script-for-database-backup) - check that answer and play around with the `date` formatting options. `%A` is for the day-of-week. – Olaf Kock Mar 04 '19 at 09:04

1 Answers1

0

My suggestion would be to create a shell script that finds the current day of the week (date +%A), then write the mysqldump output to a file formatted as "prefix"_"dayofweek" for you to zip. Then from cron, just execute this shell script rather than the mysqldump directly.

You may also find this answer helpful.

parttimeturtle
  • 1,125
  • 7
  • 22