7

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?

Shauzab Ali Rawjani
  • 256
  • 1
  • 4
  • 16
  • Important Note: you should use correct date format as mentioned below BUT the reason of this error 'Couldn't find table' is that mysql command think that you added table name after database name! so easily surround your file_name with double quotes to get rid of that error. :) – Msd.Abd Oct 08 '20 at 07:14

3 Answers3

18

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

Community
  • 1
  • 1
jaczes
  • 1,366
  • 2
  • 8
  • 16
  • it also depends if it's Windows or LINUX – jaczes Jul 25 '13 at 09:34
  • < is unexpected at this time I am writing : mysqldump -uroot -ptrackerdb) --alldatabases | bzip2 -c > $(date +%Y-%m-%d-%H.%M.%S).sql.bz2 – Shauzab Ali Rawjani Jul 25 '13 at 09:47
  • command was not useful. it wasn't useful because it is saving the file with my time and my date. i want to save it with current time and date. – Shauzab Ali Rawjani Jul 25 '13 at 10:04
  • above command saves me a gnucash_shockwave-.sql file with empty date – saimiris_devel Mar 17 '15 at 16:45
  • Important Note: you should use correct date format as mentioned above BUT the reason of this error 'Couldn't find table' is that mysql command think that you added table name after database name! so easily surround your file_name with double quotes to get rid of that error. :) – Msd.Abd Oct 08 '20 at 07:08
4

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.

Piyush Patel
  • 1,765
  • 1
  • 16
  • 29
  • Above command yields me a C:/mysql_backup_.sql file even though the date string is printed on the cmd prompt with an echo. Any hint of what it might be? – saimiris_devel Mar 17 '15 at 16:44
2

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.

Marvin Fischer
  • 2,552
  • 3
  • 23
  • 34