问题
Im using this command for backup from mysqldump
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
For this i add test_date +%Y-%m-%d_%H-%M-%S
.sql in file name but it gives error
'Couldn't find table': date +%Y-%m-%d_%H-%M-%S`
What I'm doing wrong here?
回答1:
I'm using that:
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)
@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
回答2:
In Microsoft Windows, run below command in 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
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.
回答3:
mysqldump -u Database Username --password=Database password --all-databases |gzip > /home/username/MySQLDBBK$(date +%Y_%m_%d__%H_%M_%S$%M%S).sql.gz
this Cmd is Working.
来源:https://stackoverflow.com/questions/17853838/how-to-add-date-and-time-with-backupfile-name-using-mysqldump-from-command-promp