User Functions


There are no upcoming events

What's New

Stories last 2 weeks

No new stories

Comments last 2 weeks

No new comments

Trackbacks last 2 weeks

No new trackback comments

Links last 2 weeks

No recent new links

Downloads last 2 weeks

No new files

Welcome to Geeklog Sunday, December 04 2016 @ 05:29 pm EST

Backing Up Geeklog
  • Contributed by:
  • Views:
From time-to-time on the geeklog-devel mailing list I see questions about backing up MySQL databases. The answer is pretty simple, write a shell script to do this for you, add it to your crontab or put it in one of the /etc/cron.* directories.

As some of my already know, you can use PHP as a shell scripting language. While as a pure shell language it lacks some of the power of, say, Bash, it is still a viable option for the PHP coder.

This script is a PHP shell script I wrote that will back up a MySQL database. If you already have PHP compiled as a CGI on your system (see's install docs for how to do that) then you can drop this in and it should work fine. The script keeps 7 daily backups, 4 weekly backups and 12 monthly backups which should make recovery much simpler.

In addition to the PHP CGI, you will need tar because the script will compress the database backups. For a point of reference, on my Geeklog database of over 500 stories and 450 users a backup is 1.6MB and only 515KB compressed. Give it a try and let me know what you think!

The following comments are owned by whomever posted them. This site is not responsible for what they say.

  • Thanks
  • Authored by:chmouel on Friday, February 08 2002 @ 06:35 am EST
This look good 8-), thanks a lot.
  • Thanks
  • Authored by:Anonymous on Sunday, February 10 2002 @ 11:08 am EST
This is great. I only had to modify this line:
exec(\"$mysqldump -h$mysqlhost -u$mysqluser
$database > \" . $backup_dir . \'daily/\' . $backup_file);

to remove the -p for the password.

It would be nice to have a restore procedure!!!


  • Thanks
  • Authored by:chmouel on Monday, February 11 2002 @ 04:04 am EST
Restore would not be something like :

mysql -u user -p database < file.sql

  • Thanks
  • Authored by:Anonymous on Monday, February 11 2002 @ 05:56 am EST
  • Restore needed
  • Authored by:etegration on Sunday, May 19 2002 @ 08:14 am EDT
this script seems cool but would be great if there\'s a restore script too. One more question, isn\'t there already something of a backup script in GL 1.3.5? Mine doesn\'t work, it get a Warning: OpenDir: No such file or directory (errno 2) in /home/dotcoms/etegration/domains/ on line 73
  • Thanks
  • Authored by:Anonymous on Thursday, December 12 2002 @ 04:10 pm EST
this is a great script!
after some minor tweaking it worked great. My PHP is installed as an APACHE module so I have to mess around a little more with getting it to work with lynx