Solved

Help with Shell script

Posted on 2011-03-23
8
434 Views
Last Modified: 2012-05-11
I have the following shell script to produce a backup of my database run on a cron job every 2 days.

How can I put the date in this format mm_dd_yyyy in the output filename?
mysqldump -uadmin -ppwd inve_db --all --add-drop-table -Q | gzip > "/home/backup/mysqlbu_inve_db.sql.gz" 2>>"/home/backup/logs/Errorlog.txt"

Open in new window


0
Comment
Question by:EddieShipman
8 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 35198455
> "/home/backup/mysqlbu_inve_db.sql.$(DATE '+%M_%D_%y").gz"
0
 
LVL 19

Expert Comment

by:simon3270
ID: 35198464
Oops, caps-lock invert when I pasted this!

should be:
   > "/home/backup/mysqlbu_inve_db.sql.$(date '+%m_%d_%Y").gz"
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 35198484
Not sure what's happening tody.  one more time, with feeling:

   > "/home/backup/mysqlbu_inve_db.sql.$(date '+%m_%d_%Y').gz"

(wrong quote at the end of the date format)
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 35198900
Will try it out later today.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 8

Expert Comment

by:pilson66
ID: 35199719
tstamp=$(date '+%m_%d_%Y'); mysqldump -uadmin -ppwd inve_db --all --add-drop-table -Q | gzip > "/home/backup/mysqlbu_inve_db-${tstamp}.sql.gz" 2>>"/home/backup/logs/Errorlog.txt"

Open in new window

0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 35201367
Worked perfectly. Had a problem with another script called right after it but this part worked correctly.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 35203732
I would highly recommend that you don't use ambiguous date formats.

Best to use YYYY_MM_DD

0
 
LVL 19

Expert Comment

by:simon3270
ID: 35213467
with the added benefit that files are sorted in date order automatically
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now