How to Add Date and Time Into Database Backup File Name in mysqldump

By | February 24, 2016

If you ever made backups from command line, you’d probably wanted to do this on a regular basis, including date and time of your backup (e.g. to keep backups for a week or so). Here is a simple command, that will allow you to do this:

mysqldump -h host -u user -p password database_name > backup_$(date "+%b-%d-%Y-%H-%M-%S").sql

You can specify your own format by adding or removing date parameters. This command will give you something like Feb-24-2016-12-12-13.

2 thoughts on “How to Add Date and Time Into Database Backup File Name in mysqldump

  1. aravinth nageswaran

    For 2020 use below code

    set TIMESTAMP=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%
    echo %TIMESTAMP%
    pause

    Reply

Leave a Reply to admin Cancel reply

Your email address will not be published. Required fields are marked *