RE: [PHP] getting mysql dump using php
| From: | Morgan Hughes | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | RE: [PHP] getting mysql dump using php | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125765@lists.php.net to get a copy of this message | ||
On Sun, 24 Nov 2002, Rich Gray wrote:
> Answer is No. 2)
> Use cron to run the mysqldump utility instead of a php script.
> Let me know if you need more info.
I use this one with crontab, it works pretty well, if your email program
can handle uuencode:
#!/bin/sh
# File : db_backup.sh
# Descript: Runs a ful mysqldump of one or more MySQL databases, uuencodes
# and compresses them, and mails them to a specified address.
# Requires mysqldump, gzip, uuencode, mail or mailx, and crontab.
#
# Normally this run from crontab, with an entry like:
# 0 3 * * * sh ~/db_backup
#
# Version : 1.00
# Author : Morgan Hughes (kyhm@kyhm.com)
# License : Copyright (C) 2002, Morgan Hughes. Use freely.
# Account/password/email info
db_list="your_database"
db_user="your_username"
db_pass="your_password"
email="your_email_addy"
# program locations
mysqldump="mysqldump"
dump_opts=""
uuencode="uuencode"
gzip="gzip"
mail="mail"
# Actual code
for db_name in $db_list ; do
date=
date '+%Y%m%d-%H%M%S'
$mysqldump $dump_opts -u $db_user "--password=$db_pass" $db_name | \
$gzip -c9 | $uuencode "$db_name-$date.sql.gz" | \
$mail -s "DB backup, $db_name, $date" $email
done
# Ends : db_backup.sh
At home I have a script plugged into .procmailrc with an entry like:
# First off, catch inbound automated backups.
:0
* ^Subject: DB backup, kyhm
| ~/bin/catch_backup ~/kyhm.com/backups/db
The ~/bin/catch_backup script is as follows:
#!/bin/sh
if [ "$1" != "" -a -d "$1" ] ; then
cd "$1"
else
cd ~
fi
cat | uudecode
Hope this is useful...
--
Morgan Hughes
C programmer and highly caffeinated mammal.
kyhm@kyhm.com
ICQ: 79293356