Mysql backup script available

Use GitHub to post feature requests for phpwcms.
Locked
seo-105
Posts: 23
Joined: Sun 18. Apr 2004, 00:07

Mysql backup script available

Post by seo-105 »

Hi developers:

I'm not a coding guy but I ran across a neat thread in another forum. Perhaps you would like to include the script in Phpwcms as a way to backup the mysql database periodically. Just a thought.

http://forum.powweb.com/showthread.php? ... ge=1&pp=25
SNap
Posts: 314
Joined: Wed 5. May 2004, 10:45
Location: Passau, Bavaria, Germany
Contact:

Post by SNap »

i've got a shell script which also rotates the backup-files :)

Code: Select all

#!/bin/sh
# script for backing up typo3-database of the vhb projects.
# assumptions: only backup-files are stored in the directory specified
# in the variable BACKUP_PATH

# variable stores the date in the pattern 'YYYY-MM-DD'
DATE=`date +%Y-%m-%d-%T`

# specifies the path where the backups should be stored (must exist!)
BACKUP_PATH="/somepath/backups"

# specifies how many backup files should be kept
NUMBER_OF_BACKUP_FILES=3

cd $BACKUP_PATH;

# counts the number of files in the backup directory
currentFileNum=`ls -1t | wc -l`

# if the maximal number of backup files is reached, delete the oldest file
# this is done by piping the ls-output(1 file per line and sorted descending
# according to the timestamp) into tail (only displaying the last line), and
# finally removing the file using the xargs command for passing parameters

if [ $currentFileNum -ge $NUMBER_OF_BACKUP_FILES ] ; then
    ls -1t | tail -1 | xargs -n 1 rm -fr
fi

# store bzipped mysql-dump
mysqldump -h sqlhost -u user --password="password" --opt database | gzip -c > $BACKUP_PATH/database-$DATE.sql.gz;


i call it from a cronjob via a php-script:

Code: Select all

<?php
  echo "starting backup...";
  // run shell script
  system(sprintf('./scriptname.sh'));
  echo "backup finished";
?>

Cheers
SNap
'welcome to the real world!' datensysteme-lenk
Pappnase

Post by Pappnase »

hello

i use TD-backup easy to handle. and i use this with the german http://www.cronjob.de (it's free of charge) service if you have no server!*smile*

iy ou wanna test it you can download it here.

http://www.fhss.de/td_backup.zip
SNap
Posts: 314
Joined: Wed 5. May 2004, 10:45
Location: Passau, Bavaria, Germany
Contact:

Post by SNap »

hi again,

both scripts of you are written in mysql and don't take care about rotating dump's....

And dumping with mysqldump is much faster ;) a Dump of my 60MB Database takes about 5-10 seconds. :o :D
'welcome to the real world!' datensysteme-lenk
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

SNap wrote:hi again,

both scripts of you are written in mysql and don't take care about rotating dump's....

And dumping with mysqldump is much faster ;) a Dump of my 60MB Database takes about 5-10 seconds. :o :D
what if you not have you own webserver....

Many of us use a paid webhotel....
http://www.studmed.dk Portal for doctors and medical students in Denmark
SNap
Posts: 314
Joined: Wed 5. May 2004, 10:45
Location: Passau, Bavaria, Germany
Contact:

Post by SNap »

i have just webspace, too. but with a ssh :D

you can do the plain dumping restoring with a php-script like my restore-script with sprintf() you have to ask your provider what shell-commands are availeable. Most providers put these commands like mysqldump in /cgi-bin or /phpbin or likewise....

or better: do an upgrade and get an account with ssh :)
'welcome to the real world!' datensysteme-lenk
Locked