MySQL 如何在命令提示符下使用 mysqldump 添加带有备份文件名的日期和时间并定义备份文件的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17853838/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:18:16  来源:igfitidea点击:

how to add date and time with backupfile name using mysqldump from command prompt and to define the path of backupfile

mysqlmysqldump

提问by Shauzab Ali Rawjani

Im using this command for backup from mysqldump

我使用此命令从 mysqldump 进行备份

mysqldump -uroot -ptrackerdb) --alldatabases >test.sql

mysqldump -uroot -ptrackerdb) --alldatabases >test.sql

Now i want to add date-time with my backup file like current date and time e.g test_25July2013_13:00

现在我想用我的备份文件添加日期时间,比如当前日期和时间,例如 test_25July2013_13:00

For this i add test_date +%Y-%m-%d_%H-%M-%S.sql in file name but it gives error

为此,我date +%Y-%m-%d_%H-%M-%S在文件名中添加了 test_ .sql 但它给出了错误

'Couldn't find table': date +%Y-%m-%d_%H-%M-%S`

“找不到表”:日期 +%Y-%m-%d_%H-%M-%S`

What I'm doing wrong here?

我在这里做错了什么?

回答by jaczes

I'm using that:

我正在使用它:

LINUX

LINUX

mysqldump -u <user> -p <database> | bzip2 -c > <backup>$(date +%Y-%m-%d-%H.%M.%S).sql.bz2

WINDOWS (googled it, because i have been using LIN only)

WINDOWS(用谷歌搜索,因为我一直只使用 LIN)

@echo off
cls
echo Date format = %date%
echo dd = %date:~0,2%
echo mm = %date:~3,2%
echo yyyy = %date:~6,4%
echo.
echo Time format = %time%
echo hh = %time:~0,2%
echo mm = %time:~3,2%
echo ss = %time:~6,2%
echo.
echo Timestamp = %date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%

%mysqldir%\mysqldump -u %mysqluser% -p%mysqlpassword% -h %mysqlhost% -P %mysqlport% --databases --routines --verbose gnucash_shockwave > %BackupDir%\gnucash_shockwave-%timestamp%.sql

here more info

这里有更多信息

回答by Piyush Patel

In Microsoft Windows, run below command in CMD

Microsoft Windows 中,在 CMD 中运行以下命令

mysqldump -u USERNAME -pYOURPASSWORD --all-databases > "C:/mysql_backup_%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%_%time:~3,2%_%time:~6,2%.sql"

Output file will look like,

输出文件看起来像,

mysql_backup_21-02-2015-13_07_18.sql

mysql_backup_21-02-2015-13_07_18.sql

If you want to automate the backup process, then you can use Windows Task Scheduler, and put above command in .bat file - task scheduler will run the .bat file at specified interval.

如果您想自动化备份过程,那么您可以使用 Windows 任务计划程序,并将上述命令放在 .bat 文件中 - 任务计划程序将按指定的时间间隔运行 .bat 文件。

回答by Aditya Gosavi

mysqldump -u Database Username --password=Database password --all-databases |gzip > /home/username/MySQLDBBK$(date +%Y_%m_%d__%H_%M_%S$%M%S).sql.gz

mysqldump -u 数据库用户名 --password=数据库密码 --all-databases |gzip > /home/username/MySQLDBBK$(date +%Y_%m_%d__%H_%M_%S$ %M%S).sql。 gz

this Cmd is Working.

这个命令正在工作。