Using this works, but backs up the entire hosting account. If I put the server path to the domain folder I want to backup, it doesn't work.
Suggestion on the end of the code to tar gzip the correct domain's files?
Main Topics
Browse All TopicsHow would I write a cron job to do a full domain backup and the database associated with it? I realize that each host's cron call can be slightly different.
Can this be done in a call through the cron jobs or would I actually have to write a php file to do this? I need it to weekly backup the entire domain's files in the best compression possible and then email the backup.
Can anyone help get me started with this. I've tried several out of the box programs, but none seem to quite do the job right or complete. Example: one will only do a db, another can't handle the large site, another won't work outside of a subfolder and can't be put in the root.
I was hoping this would be something fairly simple to throw together since there's no need to exclude or restore anything. Then just adapt it per domain that it's to be used on.
None of the hosting involves windows servers.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>>> If I put the server path to the domain folder I want to backup, it doesn't work.
How doesn't it work? What is the command, what is the expected result, and what is the actual result?
If you are calling this script from cron, doing this through PHP just adds a level of unnecessary complexity. You would be better off using basic shell commands (i.e., the same command, without the PHP system() call) to create the archives, move the file to somewhere accessible to your command-line PHP environment, then using PHP to just construct the outbound email.
I'm mostly doing it this way so that it's quicker to edit for each domain that it will go on - and because I don't know shell. I don't have cron set yet.
What I meant by "it doesn't work" - it just doesn't do anything at all. Doesn't save a backup file or gzip anything. But leaving it as is backs up the whole hosting account.
What I need it to do is backup to gzip an entire domain plus all db's related to that domain (I'll make sure all dbs to be backed up have a common user with the right permissions). Then email it.
Then I need to do a separate script that does all the work to put it back if needed. The concern recently is if I'm not available anyone that would need to fix something asap would have no experience to restore it unless they could just upload the backups and a file to run to do the work for them.
>>> and because I don't know shell.
You're making this out to be more difficult than it is. Keep it simple. The command you passed to the system() call is a shell command. While there are some commands internal to the shell (like cp, mv, etc.), most of what you want is just calling external programs from the shell, such as gzip. Generally, you can figure out how to use each of the programs you need by using the --help switch when running them. For example:
tar --help
gzip --help
You can also use "man <command>" for most of the popular commands and applications. Try "man tar" from your shell prompt.
See the example shell session below for how this works. Once you have that part working, you can modify your script to use a command-line parameter. That way, a backup/restore user can use the same script for multiple domains/directories/databa
http://www.ibm.com/develop
Business Accounts
Answer for Membership
by: routinetPosted on 2009-10-29 at 01:43:36ID: 25691574
Fortunately, this task is surprisingly simple.
cron is simply a program which launches other programs on a schedule. The target program can be anything, including shell scripts. If you already know the shell commands you need to run in order to complete a backup, just put those commands into a shell script and have cron run it. For MySQL, use the mysqldump command to generate an SQL backup including the data. For the web site, run tar/zip/gzip/bzip to compress everything from the document root down.
The emailing part is a little more complex, depending on how your mail services are setup. I'm not entirely sure how to attach a file to an email from command line, but using PHP to generate the email instead makes this process simple as well. At the end of your shell script, run a PHP page from command line. You can code it to accept parameters, such as the 'To' address, and the file to attach.