snippetsqlMinor
How to generate a dynamic file name for a mysqldump on Linux?
Viewed 0 times
filehowmysqldumpgeneratenameforlinuxdynamic
Problem
I want to schedule my MySql backs to happen on an hourly basis, but the problem is I want to customize the name of the file that is outputs but not to sure how to?
This is the command I am using now
This works but I would to have it output a file something like this, but for it to happen dynamically, when the command is run
How could I do this on a single line of code
This is the command I am using now
mysqldump -u yourusername -h yourusername.mysql.pythonanywhere-services.com 'yourusername$dbname' > db-backup.sqlThis works but I would to have it output a file something like this, but for it to happen dynamically, when the command is run
1-01-18.13:50.db-backup.sqlHow could I do this on a single line of code
Solution
This should do it :
Will generate files like :
If you want to compress the file on the fly :
mysqldump -u yourusername -h yourusername.mysql.pythonanywhere-services.com 'yourusername$dbname' > `date +"\%Y-\%m-\%d_\%H-\%M"`.db-backup.sqlWill generate files like :
2018-01-01_13-50.db-backup.sql. You can adapt this to whatever exact format you want (but you should avoid using special characters such as :).If you want to compress the file on the fly :
mysqldump -u yourusername -h yourusername.mysql.pythonanywhere-services.com 'yourusername$dbname' | gzip > `date +"\%Y-\%m-\%d_\%H-\%M"`.db-backup.sql.gzCode Snippets
mysqldump -u yourusername -h yourusername.mysql.pythonanywhere-services.com 'yourusername$dbname' > `date +"\%Y-\%m-\%d_\%H-\%M"`.db-backup.sqlmysqldump -u yourusername -h yourusername.mysql.pythonanywhere-services.com 'yourusername$dbname' | gzip > `date +"\%Y-\%m-\%d_\%H-\%M"`.db-backup.sql.gzContext
StackExchange Database Administrators Q#226123, answer score: 2
Revisions (0)
No revisions yet.