bash 带时间戳的 Mysql 转储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23518104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mysql dump with timestamp
提问by Ayman
I have a project that uses MySQL database. I want to backup the database every day, so I use this:
我有一个使用 MySQL 数据库的项目。我想每天备份数据库,所以我用这个:
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
今天文件将被命名为something-07-05-2014 08-00-00
明天将是,something-08-05-2014 08-00-00
How to append a formatted timestamp with the exported file name ?
如何在导出的文件名中附加格式化的时间戳?
回答by Pranav Maniar
You can use something like this
你可以使用这样的东西
mysqldump -h host -u user -p password database > $(date "+%b_%d_%Y_%H_%M_%S").sql
回答by user3470953
you can do
你可以做
mysqldump -h host -u user -p password database > something-$(date +%d-%m-%Y %H %M %S).sql