[drupal-support] automatically do database backups?

Pontus Ullgren ullgren at users.sourceforge.net
Thu Apr 14 11:10:47 UTC 2005


Anisa said:
>
>
> Gerhard Killesreiter wrote:
>
>>
>>No cron jobs no automatism.
>>
>>You could write a script that is executed through cron.php though and
use poormanscron.
>>
>>
>>
> Aw.  I can actually run cron jobs on my server, I just need to read up
more.
>
Then I would suggest to set up a normal cronjob using a simple shell
script and mysqldump (or any other simulare util for your database). -----
#!/bin/sh
#
# Backup script for a MySQL databases.
#
if [ -z $1 ]; then
   echo "usage: $0 databasename";
   exit 1;
fi

# Change to your backup place
OUTPUTDIR=/tmp

TODAY=`date +%Y-%m-%d`
mysqldump --defaults-file=backup.cnf  $1 > $OUTPUTDIR/$1\_$TODAY.sql

# You can use this instead to compress the file on the fly
# mysqldump --defaults-file=backup.cnf  $1 | \
#   gzip - > $OUTPUTDIR/$1\_$TODAY.sql.gz
-----

backup.cnf must contain the host, username and password it should only the
readable to your user (or the user running cron).
---
[client]
host     = 127.0.0.1
user     = drupal
password = drupal
---

Then add something like this to the crontab:
0 1 * * *    /path/to/dbbackup.sh databasename

> Anisa.
> --
> [ Drupal support list | http://lists.drupal.org/ ]






More information about the drupal-support mailing list