Find the answer to your Linux question:
Results 1 to 4 of 4
Hi everyone, I am running a script on my website which created a dump of a mysql database and saves it onto the system. It looks like this, mysqldump --opt ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2007
    Posts
    5

    Prefixing a file name with the date


    Hi everyone, I am running a script on my website which created a dump of a mysql database and saves it onto the system. It looks like this,

    mysqldump --opt -hlocalhost -uuser -ppassword database | gzip > /path/for/file/mysqlbackup.gz

    How could prefix mysqlbackup.gz with the current time and date baring in mind that this script is to be run automatically with cron.

    Secondly does anyone know how I could then email this file, again running from the same cron function?

  2. #2
    Just Joined!
    Join Date
    Dec 2006
    Posts
    52
    I can suggest with the date issue to create a variable and use the date command:
    dte=`date`
    mysqldump --opt -hlocalhost -uuser -ppassword database | gzip \ > /path/for/file/${dte}mysqlbackup.gz
    (in bash that is how it would be done)
    Mailing depends on what language you are running the script in...Most scripting languages have mail type functions built in...

  3. #3
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,790
    Quote Originally Posted by ennoil
    I can suggest with the date issue to create a variable and use the date command:
    dte=`date`
    Can i also add, that looking into the date man pages may help fir getting a suitable format since the default will probably show the times with a ":" which is not the best idea. Personally i'd use something like:

    Code:
    mysqldump -u <user> -p<password> database > database-` date "+%d-%m-%Y %H:%M:%S"`.sql
    This will name the file: database-31-01-07 12:00:01.sql

    Obviously you can play with the format of the date, just change the % values and the relevent seperators, but do make sure it's in "" else any spaces will not show properly. And also in the command, if you want to gzip it, then you obviously know how to do that from above, i personally prefer not to though.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  4. #4
    Just Joined!
    Join Date
    Jan 2007
    Posts
    5
    I keep getting a ambiguous redirect error message. Whats does this mean?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •