-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbackup-wiki-php-net
executable file
·70 lines (57 loc) · 1.72 KB
/
backup-wiki-php-net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# $Id$
# Backup the Wiki data: pages and media
# The wiki code itself is in CVS
#
# config
WIKIPATH="/home/web/wiki.php.net/public_html" # path to your wiki, no symbolic are links allowed!
BACKUPPATH="/local/this-box/wiki.php.net" # where do you save the backups?
DAILY_DATA_BACKUPS="2" # keep this amount data backups
DAILY_MEDIA_BACKUPS="2" # 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}" "data/media"
# for debian etch, replace "media" by "data/media" in line above
# and add --excude="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"