Hi, On Mon, Feb 21, 2000 at 10:24 -0600, Jon Pennington wrote:
Ooh! I know this one! :) Have a look at my backup script for my one and only MySQL database (I'm particularly proud of this):
#!/bin/sh # Script to create daily backups of the IRM database mysqldump -u root -ppassword irm > /tmp/irm-`date '+%y%m%d'`.dump # Makes an sql dump of the irm database in /tmp
gzip /tmp/irm-`date '+%y%m%d'`.dump # Compresses the file
IRM_BACKUP=irm-`date '+%y%m%d'`.dump.gz ; export IRM_BACKUP # Less typing down the road ;)
mv /tmp/$IRM_BACKUP /home/jpennington # Moves the file to a remote location
chown jpennington.users /home/jpennington/$IRM_BACKUP chmod 600 /home/jpennington/$IRM_BACKUP # Makes the file irmadmin's property
echo "$IRM_BACKUP has been created" | mail jpennington -s $IRM_BACKUP # Notifies user that the cron job terminated successfully # EOF
I'm also fishing for some suggestions concerning the script in general. I need to integrate some error-trapping with this, since my script will go merrily about it's business wether the file was created or not. Ideas? :)
You run date several times and expect it to return the same value every time. Think about what your script would do if it was started at 11:59.59 pm. Better store the current date in a varible and use that whenever you need it.
mysqldump -u root -ppassword irm > /tmp/irm-`date '+%y%m%d'`.dump
Before you do this, check if /tmp/irm-`date '+%y%m%d'`.dump already exists and if it is a symbolic link. Some malicious user could create a symbolic link with that name that points to an arbitrary file. When your backup script is invoked with root privileges, it will overwrite that file. The same for
gzip /tmp/irm-`date '+%y%m%d'`.dump
This won't overwrite /tmp/irm-`date '+%y%m%d'`.dump.gz but if this file already exists, gzip will probably ask you if it may overwrite it and wait forever.
IRM_BACKUP=irm-`date '+%y%m%d'`.dump.gz ; export IRM_BACKUP ^^^^^^^^^^^^^^^^^^^ That's not necessary.
echo "$IRM_BACKUP has been created" | mail jpennington -s $IRM_BACKUP
You'll receive this message even if your script failed to create a backup. To remedy this you might want to use something like dothis && dothat && anddothattoo && echo "done" |mail jpennington -s "done" || echo "failed" |mail jpennington -s "failed" Ciao, Stefan -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/