wok-stable view mirror-tools/stuff/home/backups/mirror/backup.sh @ rev 6934
ntpclient: one call in crontab only
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Oct 23 12:53:58 2010 +0200 (2010-10-23) |
parents | 0c59b115eabd |
children | bea570b9faaa |
line source
1 #!/bin/sh
3 KEEP=1
4 EXTRA="monthly:30:2"
5 BACKUP_USER=bellard
6 REMOTE_USER=bellard
8 backup_data()
9 {
10 while read file dirs; do
11 ( cd / ; find $dirs | cpio -o -H newc ) | \
12 rgzip -9 > $file.cpio.gz 2> /dev/null
13 done <<EOT
14 etc etc home/$BACKUP_USER/.ssh
15 www var/www/mirror-info var/www/pizza
16 packages var/lib/tazpkg/installed
17 rrd var/spool/rrd
18 crontabs var/spool/cron/crontabs
19 awstats var/lib/awstats
20 EOT
21 }
23 #
24 # The following should be kept untouched.
25 #
27 SSH="ssh -i /home/$BACKUP_USER/.ssh/id_rsa"
29 cd $(dirname $0)
30 [ $(id -u) == 0 ] || exit 1
31 [ $(hostname) == $(basename $PWD) ] || exit 1
33 rotate()
34 {
35 local i
36 local j
37 for j in $(seq $(($1 - 1)) -1 1); do
38 for i in *.$2.$(($j - 1)) ; do
39 [ -e $i ] && mv -f $i ${i%.$2.*}.$2.$j
40 done
41 done
42 }
44 [ -n "$EXTRA" ] && for x in $EXTRA ; do
45 IFS=':' ; set -- $x ; unset IFS
46 suffix=$1
47 days=$2
48 keep=$3
49 for i in *.gz ; do
50 [ -e $i ] || continue
51 mtime=$(( $(stat -c %Y $i) - ($days * 24 * 3600) ))
52 j=$i.$suffix.0
53 [ -e $j ] && [ $(stat -c %Y $j) -gt $mtime ] && continue
54 rotate $keep gz.$suffix
55 ln $i $j
56 done
57 done
58 if [ 0$KEEP -gt 0 ]; then
59 [ $KEEP -gt 1 ] && rotate $KEEP gz
60 for i in *.gz ; do
61 [ -e $i ] && mv -f $i $i.0
62 done
63 fi
65 backup_data
67 chown $BACKUP_USER *
68 chmod 700 *
70 [ -n "$REMOTE_USER" ] && for i in $(cd .. ; ls); do
71 [ $i == $(hostname) ] && continue
72 rsync -aH -e "$SSH" --bwlimit=50 $REMOTE_USER@$i.slitaz.org:/home/backups/$i/. ../$i/.
73 done