====== Backup data from dokuwiki ======
Use this if you lost your ftp access, for example. You MUST allow php in pages to use this. This includes PEAR and Archive_Tar, and works in SAFE mode. It's completly insecure, the tar.gz file remains after use.
__**USE ONLY WHEN ALL OTHER MEANS HAVE FAILED**__
[[tips:backup_script_data|Copypaste the contents of this file into a doku page on your wiki]]
====== One-time backup ======
This backs up the entire dokuwiki directory into a bz2 tar file. It is a simplified version of the script below. The commands are most likely to be run manually. The commands assume that you are in the parent directory of the dokuwiki install. My entire dokuwiki is in ~/wiki ((tilde ~ means home directory, the actual full path is longer)). I ran this from ~ . The second and third commands are not **really** needed, but if you want to have multiple backups, it may help
cd ~
mkdir wikibackup
cd wikibackup/
tar -cjf wiki.tar.bz2 ../wiki
===== Alternate command =====
A version of the above, with the addition of the current date to the filename.
tar -cjf backupDir/wiki.`date '+%d%m%y'`.tar.bz2 ../wiki
====== Backup Script ======
This small Bash-Shellscript (probably works with other shells too) creates backups of your wiki data/ and media/ directories. It keeps several old backups (see config) and archive backups, created on the first day of the month. You should put it in cron.daily, otherwise it does not really work like intended.
-- dp
#!/bin/sh
# $Id: dw-backup.sh 328 2004-12-22 13:15:20Z dp $
# config
WIKIPATH="/home/dp/www/dokuwiki" # path to your wiki, no symbolic links are allowed!
# for debian etch: /var/lib/dokuwiki
BACKUPPATH="/home/dp/dw-backup" # where do you save the backups?
DAILY_DATA_BACKUPS="8" # keep this amount data backups
DAILY_MEDIA_BACKUPS="3" # and media backups
# no more config
# creates $1, if not existant
checkDir()
{
if [ ! -d "${BACKUPPATH}/$1" ]
then
mkdir -p "${BACKUPPATH}/$1"
fi
}
# 1 -> path
# 2 -> name
# 3 -> number of backups
rotateDir()
{
for i in `seq $(($3 - 1)) -1 1`
do
if [ -f "$1/$2.$i.tar.bz2" ]
then
mv "$1/$2.$i.tar.bz2" "$1/$2.$((i + 1)).tar.bz2"
fi
done
}
# make sure everything exists
checkDir "data"
checkDir "data/archive"
checkDir "data/daily"
checkDir "media"
checkDir "media/archive"
checkDir "media/daily"
# first step: rotate daily.
rotateDir "${BACKUPPATH}/data/daily" "data" "$DAILY_DATA_BACKUPS"
rotateDir "${BACKUPPATH}/media/daily" "media" "$DAILY_MEDIA_BACKUPS"
# then create our backup
# --exclude is not accepted for Linksys NSLU2 box, any alternative?
tar --exclude=".*" -cjf "/tmp/data.1.tar.bz2" -C "${WIKIPATH}" "data"
tar --exclude=".*" -cjf "/tmp/media.1.tar.bz2" -C "${WIKIPATH}" "media"
# for debian etch, replace "media" by "data/media" in line above
# and add --exclude="media" to first tar line
# create an archive backup?
if [ `date +%d` = "01" ]
then
cp "/tmp/data.1.tar.bz2" "${BACKUPPATH}/data/archive/data-"`date +%m-%d-%Y`".tar.bz2"
cp "/tmp/media.1.tar.bz2" "${BACKUPPATH}/media/archive/media-"`date +%m-%d-%Y`".tar.bz2"
fi
# add them to daily.
mv "/tmp/data.1.tar.bz2" "${BACKUPPATH}/data/daily"
mv "/tmp/media.1.tar.bz2" "${BACKUPPATH}/media/daily"
===== An rsync alternative =====
The script above works perfectly fine, thanks!
That being said, for bigger wiki sites the archive might grow very big with a daily tar file of the whole web site, especially the ''media'' directory. \\
Furthermore, I'd like to be able to run the backup script on a trusted and more secure server. Thus here is another way of doing the backup, possibly on another server, that will keep only one copy of the site plus daily differences using ''rsync''.
This script is far from being well written, so please feel free to do any improvements you like!
#!/bin/bash
#========================
# backup script for stuff on wiki to be run periodically through a crontab on a trusted server
# > crontab -e
#
# daily : 1 1 * * * /path/to/script/wwwbackup.sh
# weekly: 1 1 * * 0 /path/to/script/wwwbackup.sh # I Guess weekly backup is enough for not frequetly updated wiki
#========================
here=`pwd`
mydate="`date '+%Y%m%d.%H%M'`"
# Define wiki location
myhost='www' #name of the server hosting your your wiki
myuser='user' #name of the user that has an ssh access to "myhost"
relpathtowiki='relpath/to/wiki/' #relative path to your wiki from "myhost" base
backupsource="${myuser}@${myhost}:${relpathtowiki}"
#backupsource="/abs/path/to/wiki/" #Use this line instead of the above if you run the backup script directly on your www server.
# Define location of backup
backupdir="/path/to/backup/${myhost}"
logfile="${backupdir}/backup.log"
excludelist="${here}/wwwbackup-exclude-list.txt"
bkname="backup"
nbbackup="7" # keep this amount of old backup
#-- creates $1, if not existant
checkDir() {
if [ ! -d "${backupdir}/$1" ] ; then
mkdir -p "${backupdir}/$1"
fi
}
# 1 -> path
# 2 -> name
# 3 -> number of backups
rotateDir() {
for i in `seq $(($3 - 1)) -1 0`
do
if [ -d "$1/$2-$i" ] ; then
/bin/rm -f "$1/$2-$((i + 1))"
mv "$1/$2-$i" "$1/$2-$((i + 1))"
fi
done
}
#-- make sure everything exists
checkDir "archive"
checkDir "daily"
#-- first step: rotate daily.
rotateDir "${backupdir}/daily" "$bkname" "$nbbackup"
mv ${logfile} ${backupdir}/daily/${bkname}-1/
cat >> ${logfile} <<_EOF
===========================================
Backup done on: $mydate
===========================================
_EOF
#-- Do the backup and save difference in backup-1
mkdir -p ${backupdir}/daily/${bkname}-1/
mkdir -p ${backupdir}/daily/${bkname}-0/
cd ${backupdir}/daily/${bkname}-0
rsync -av --whole-file --delete --force \
-b --backup-dir ${backupdir}/daily/${bkname}-1/${thisdir} \
--exclude-from=${excludelist} \
$backupsource . \
1>> ${logfile} 2>&1
#-- create an archive backup every month
lastarchivetime="0"
if [ -r ${backupdir}/lastarchivetime ] ; then
lastarchivetime=`cat ${backupdir}/lastarchivetime`
fi
now=`date +%j`
let diffday=$now-$lastarchivetime
if [ $diffday -ge 30 -o $diffday -lt 0 ] ; then
echo $now > ${backupdir}/lastarchivetime
cd ${backupdir}/daily
tar -cjf ${backupdir}/archive/${bkname}-${mydate}.tar.bz2 ./${bkname}-0
fi
The script uses an //exclude// file, listing all file and dir "pattern name" you wish not to include in the backup.\\
Here is a copy of my ''wwwbackup-exclude-list.txt'' file:
data/.cache/*
===== Download a copy of your wiki installation =====
Place this script in your DokuWiki directory and give your web server the rights to execute it, and you'll be able to download a compressed copy of your entire dokuwiki installation.
**Note:** The script uses an //exclude// file to avoid certain files to be included in your backup (for example your cache dir)
#!/bin/bash
echo Content-type: application/octet-stream; name="dokuwiki.tar.bz2"
echo Content-disposition: filename="dokuwiki.tar.bz2"
echo
tar --exclude-from=.excluir -cvjO ../dokuwiki/
> How would you actually download the tarball? A link in the wiki? -- samaritan
>> You can just enter the URL manually. It should look like this: ''%%http://yourhost.com/yourwikidir/backupscript.cgi%%'' --- //[[chris@chrisarndt.de|ChristopherArndt]] 2005-10-17 13:12//
===== Download a copy of your wiki installation (PHP version) =====
I like the elegance of the bash script, but some installations may not have .cgi or shells as a processing option. Since PHP is a given, it makes sense to work from there.
Header redirects often confuse browsers, so we'll sacrifice a some file space rather than just a pipe. This has the side effect of leaving a file we can grab again if the download chokes, which can be useful.
$dumpFile");
rename($dumpFile, "$fullPath/$archFile");
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$archFile");
exit;
?>
A more agnostic version of this could be done with the PEAR Tar class, but this works fine on unix type installations.
//[[baavgai@chaingang.org|Baavgai]] 2007-06-08 22:24//
===== Download a copy of your wiki installation (pure PHP version) =====
For completeness, here's a PEAR Tar version of the above. It should work on any box, including Windows, that has the PHP libraries.
//[[baavgai@chaingang.org|Baavgai]] 2007-06-13 08:37//
createModify(array($fullPath), "dokuwiki", $fullPath);
# keep absolute
# $tar->create($files);
rename($dumpFile, "$fullPath/$archFile");
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
header("Location: http://$host$uri/$archFile");
exit;
?>
===== Download a copy of your wiki installation (modified PHP version) =====
A slightly modified version of the above. Doesn't make use of ''header("Location:...''. Put it as, e.g., "dump.php" to the root of your DokuWiki installation and open the appropriate URL in your web browser. After saving ''dokuwiki_YYYY-MM-DD_hh-mm-ss.tar.gz'' to your local computer, remove both files to avoid security risks.
$title
$title
Dumping local folder "$fullPath"
to archive "$archFile"...
END;
$tar = new Archive_Tar($dumpFile, "gz");
$tar->createModify(array($fullPath), "dokuwiki", $fullPath);
if (file_exists($dumpFile)) {
rename($dumpFile, "$fullPath/$archFile");
echo <<Result: successful
Download: $archFile
END;
}
else {
echo <<Result: failed
END;
}
echo <<
END;
?>
===== (Yet Another) PHP script to download a copy of your DokuWiki installation =====
* Does not use intermediate $dumpFile
* Uses Content-Disposition
* Deletes backup file prior exit
' . basename($archive));
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($archive) . '"');
readfile($archive);
unlink($archive);
?>
//[[http://dreamlusion.eucoding.com|dreamlusion]] 2008/3/9 16:00:00//
===== windows command line script =====
Although wndows "ms dos shell" is not powerful as Unix shells, it can handle a lot of problems with or without third party programs ([[http://www.robvanderwoude.com/batchfiles.php|Some examples]]). For this script you must install (or unzip) the [[http://www.ncftp.com/ncftp/|ncftp client executables]], and then you can run the following script:
@echo off
rem place this script in the parent directory of dokuBackup folder.
IF EXIST dokuBackup (
echo dokuBackup already exist
echo renaming ...
IF EXIST dokuBackup_old (
echo are you confused? dokuBackup_old already exist!
exit /B 1
) ELSE (
move /Y dokuBackup dokuBackup_old
)
) ELSE (
mkdir dokuBackup
)
ncftpget -R -u yourUsername -p yourPassword yourWebspaceFTPurl "./dokuBackup" "yourWebSpaceFtpDokuwikiPath/conf"
ncftpget -R -u yourUsername -p yourPassword yourWebspaceFTPurl "./dokuBackup" "yourWebSpaceFtpDokuwikiPath/data/pages"
ncftpget -R -u yourUsername -p yourPassword yourWebspaceFTPurl "./dokuBackup" "yourWebSpaceFtpDokuwikiPath/data/meta"
ncftpget -R -u yourUsername -p yourPassword yourWebspaceFTPurl "./dokuBackup" "yourWebSpaceFtpDokuwikiPath/media"
ncftpget -R -u yourUsername -p yourPassword yourWebspaceFTPurl "./dokuBackup" "yourWebSpaceFtpDokuwikiPath/attic"
===== Via FTP using wget =====
FTP-Login stored in //$HOME/.netrc//
machine example.net login USER password PW
#!/bin/sh -e
# backup data from wiki (FTP)
unset
url="ftp://example.net/"
backup="/path/to/backup"
wget -q --no-cache -nH -c -t0 --mirror -P$backup -i- <
See ''wget --help'' for details.