PDA

View Full Version : Which is less server intense?


phppete
05-13-2006, 06:03 AM
When sending a database backup by email for example, which would be the preferred method:

1) Using something like PHPMailer and emailing via the typical PHP route
2) Shell script: uuencode 01-05-2006_forum.sql.gz 01-05-2006_forum.sql.gz | mail info@emailaddress.com

I have to confess I only just found out how easy it is to send email attachments via a shell script, assuming there isnt anything I have missed, this would seem like a far better alternative to using PHP. I have numerous DB backup PHP scripts running via cronjobs on many FQ servers for clients. I would like to redo these avoiding PHP and just using a shell script, less code, easier to maintain. Is there any reason why I shouldn't do this?

Thanks

Terra
05-13-2006, 09:30 AM
Either is fine, just depends on your preference... ;)

--
Terra
sysAdmin
FutureQuest

phppete
05-13-2006, 10:33 AM
Hi Terra,

Thanks for the reply, the shell script is by far the most maintainable and easier. FWIW if anyone is interested this script backs up your database, emails it to you and stores it on the server. Then it deletes any file over 30 days old (but obviously you can change that, change +30 to however many days).

#!/bin/sh
mydate=$(date +%d-%m-%Y)
sitename=forum_name
username=xdomain
password=password
host=MySQL.domain.co.uk
database=xdomain-forum
path=/big/dom/xdomain/sqlbk/forum/
/usr/local/mysql/bin/mysqldump -q -e -h${host} -u${username} -p${password} ${database} | gzip - > ${path}${mydate}_${sitename}.sql.gz
uuencode ${path}${mydate}_${sitename}.sql.gz ${mydate}_${sitename}.sql.gz | mail -s "Database Backup ${sitename}" info@email_to_send_it_to.co.uk
find ${path} -type f -mtime +30 -exec rm {} \;