automatically backing up via email?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

automatically backing up via email?

Post by titaniumdoughnut »

I hope this isn't a dumb question, but I've done a bit of searching and can't find anything.

The tools I have available are a Linux server, c-panel and phpMyAdmin.

I'm trying to figure out a way to schedule automatic backups of the mySQL databases. The only safe place I can think of to put the backed-up files is my gmail account, seeing as all my websites are on the same server.

Is there a way to do this? Could a cron job with some kind of PHP script do it? I know nothing about this type of thing.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Hi,

If you have a way to use cron jobs, you may start your backups automatically.
If not, you may (mis-)use a well visited website to call you backup script. With each visit you may check whether it's time to do a backup.

backup scripts: there are some scripts special made for backing up databases. You only need PHP and your database for this.
Some of these scripts directly allow sending backups per email, ftp them to other servers or just store them on the current server. (Customizing them to send email should not be too difficult).

djot
-
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Something simple as the following script could already be sufficient (untested)

Code: Select all

#!/bin/bash
# notice the lack of a space between -p and password
mysqldump -u username -ppassword -h hostname databasename | mail user@example.com -s &quote;this is the backup of `date +%Y-%m-%d`&quote;
You can also place a tar or bz2 in between ;)
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

Post by titaniumdoughnut »

Thanks :)

djot, very clever. There aren't any visitor-up-dateable bits of data, so I could test to see if it's time to backup whenever an admin logs in.

Tim, that looks amazingly simple... the only trouble is, I don't know what it is 8O

What type of script is it? Where do I put it and how do I call it?

Thanks guys.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
? if you don't have access to cronjobs, nor may use shell scripts (what is above from timvw) you will have to use a way like I described, where one website calls backup scripts on another website. And yes, this is very clever :)

djot
-
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

Post by titaniumdoughnut »

I'm going to try running that as a cron job today, and see what happens. thanks!

ps - if my site goes down, send for help ;)
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

Post by titaniumdoughnut »

hmm... I filled it out to the best of my ability (un and pw are for the database user, right?) and put it into the cron tab, set to execute every minute, for testing. Then, after I submitted it, it just disappeared, and the cron tab is still empty. I'm afraid to poke around further, because I haven't a clue what I'm doing.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

How have you installed it in the crontab?? I've fot a feeling you are using something like CPanel etc...


If you have shell access you can use "crontab -e" to edit your crontab file..
Or "crontab -l" to list the file..

It could look like

Code: Select all

1               3  *  *  *      /usr/bin/mysqldump -u timvw -ppassword databasename | /usr/bin/mail timvw@gmail.com -s &quote;MySQL backup of `date +%Y-%m-%d`&quote;

# *             *  *  *  *      * 
# |             |  |  |  |      |
# |             |  |  |  |      +--------- command to be executed
# |             |  |  |  +---------------- day of week (1 - 7) (monday = 1) 
# |             |  |  +------------------- month (1 - 12)
# |             |  +---------------------- day of month (1 - 31)
# |             +------------------------- hour (0 - 23)
# +--------------------------------------- min (0 - 59)
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

Post by titaniumdoughnut »

Yes, I did use C-panel... is that bad?

I'll poke around a bit and try to figure out if I have shell access. How would I log in? Do you have to use a special program? Could I use the OS X Terminal?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I have absolutely no experience with CPanel and friends, so i can't say if they are good/bad/whatever..


I login with a SSH2 client.. I don't know OSX terminal, so can't help you there..

But it all comes down to editting your crontab file.. and isntalling it.. no matter how you do it.
User avatar
titaniumdoughnut
Forum Commoner
Posts: 33
Joined: Wed Jul 13, 2005 2:02 pm
Location: Manhattan

Post by titaniumdoughnut »

thanks :)

I'll get this working eventually! You've been very helpful.
Post Reply