Ayman
Ayman

Reputation: 1463

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 ?

Upvotes: 8

Views: 23545

Answers (2)

Pranav Maniar
Pranav Maniar

Reputation: 1565

You can use something like this

mysqldump -h host -u user -p password database >  $(date "+%b_%d_%Y_%H_%M_%S").sql

Upvotes: 22

user3470953
user3470953

Reputation: 11315

you can do

mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql

Upvotes: 11

Related Questions