Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql dump with timestamp

I have a project that uses MySQL database. I want to backup the database every day, so I use this:

mysqldump -h host -u user -p password database > 'location.sql'

I want the files to be named with timestamp, i.e.:

Today the file will be named something-07-05-2014 08-00-00
Tomorrow will be, something-08-05-2014 08-00-00

How to append a formatted timestamp with the exported file name ?

like image 831
Ayman Avatar asked May 07 '14 12:05

Ayman


2 Answers

You can use something like this

mysqldump -h host -u user -p password database >  $(date "+%b_%d_%Y_%H_%M_%S").sql
like image 161
Pranav Maniar Avatar answered Oct 16 '22 18:10

Pranav Maniar


you can do

mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql
like image 28
user3470953 Avatar answered Oct 16 '22 16:10

user3470953