wok annotate mirror-tools/stuff/home/backups/mirror/backup.sh @ rev 8293
Up: slitaz-tools-boxes to 4.0.3.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Sun Jan 30 23:48:19 2011 +0000 (2011-01-30) |
parents | 872280fb02fc |
children |
rev | line source |
---|---|
pascal@5649 | 1 #!/bin/sh |
pascal@5649 | 2 |
pascal@5649 | 3 KEEP=1 |
pascal@5649 | 4 EXTRA="monthly:30:2" |
pascal@5649 | 5 BACKUP_USER=bellard |
pascal@5649 | 6 REMOTE_USER=bellard |
pascal@5649 | 7 |
pascal@5649 | 8 backup_data() |
pascal@5649 | 9 { |
pascal@7324 | 10 GZIP=rgzip |
pascal@7324 | 11 which $GZIP > /dev/null || GZIP=gzip |
pascal@7324 | 12 echo "Sync doc.slitaz.org ..." |
pascal@7324 | 13 rsync -aH -e "$SSH" --bwlimit=50 \ |
pascal@7324 | 14 $REMOTE_USER@tank.slitaz.org:/home/slitaz/www/doc/data/. /var/www/doc/data/. |
pascal@5649 | 15 while read file dirs; do |
pascal@7324 | 16 echo "Create $file.cpio.gz ..." |
pascal@5677 | 17 ( cd / ; find $dirs | cpio -o -H newc ) | \ |
pascal@7324 | 18 $GZIP -9 > $file.cpio.gz 2> /dev/null |
pascal@5649 | 19 done <<EOT |
pascal@5677 | 20 etc etc home/$BACKUP_USER/.ssh |
pascal@5677 | 21 www var/www/mirror-info var/www/pizza |
pascal@7324 | 22 www2 var/www/boot /var/www/hg /var/www/pkgs /var/www/doc |
pascal@5677 | 23 packages var/lib/tazpkg/installed |
pascal@5677 | 24 rrd var/spool/rrd |
pascal@5677 | 25 crontabs var/spool/cron/crontabs |
pascal@5677 | 26 awstats var/lib/awstats |
pascal@5649 | 27 EOT |
pascal@5649 | 28 } |
pascal@5649 | 29 |
pascal@5649 | 30 # |
pascal@5649 | 31 # The following should be kept untouched. |
pascal@5649 | 32 # |
pascal@5649 | 33 |
pascal@7324 | 34 SSH="ssh -i /home/$BACKUP_USER/.ssh/id_rsa -o PasswordAuthentication=no" |
pascal@5649 | 35 |
pascal@5649 | 36 cd $(dirname $0) |
pascal@5649 | 37 [ $(id -u) == 0 ] || exit 1 |
pascal@7324 | 38 [ $(hostname) == $(basename $PWD) -o \ |
pascal@7324 | 39 $(hostname) == $(basename $PWD).slitaz.org ] || exit 1 |
pascal@5649 | 40 |
pascal@5649 | 41 rotate() |
pascal@5649 | 42 { |
pascal@5649 | 43 local i |
pascal@5649 | 44 local j |
pascal@5649 | 45 for j in $(seq $(($1 - 1)) -1 1); do |
pascal@5677 | 46 for i in *.$2.$(($j - 1)) ; do |
pascal@5678 | 47 [ -e $i ] && mv -f $i ${i%.$2.*}.$2.$j |
pascal@5677 | 48 done |
pascal@5649 | 49 done |
pascal@5649 | 50 } |
pascal@5649 | 51 |
pascal@5649 | 52 [ -n "$EXTRA" ] && for x in $EXTRA ; do |
pascal@5649 | 53 IFS=':' ; set -- $x ; unset IFS |
pascal@5649 | 54 suffix=$1 |
pascal@5649 | 55 days=$2 |
pascal@5649 | 56 keep=$3 |
pascal@5649 | 57 for i in *.gz ; do |
pascal@5677 | 58 [ -e $i ] || continue |
pascal@5649 | 59 mtime=$(( $(stat -c %Y $i) - ($days * 24 * 3600) )) |
pascal@5649 | 60 j=$i.$suffix.0 |
pascal@5649 | 61 [ -e $j ] && [ $(stat -c %Y $j) -gt $mtime ] && continue |
pascal@5649 | 62 rotate $keep gz.$suffix |
pascal@5649 | 63 ln $i $j |
pascal@5649 | 64 done |
pascal@5649 | 65 done |
pascal@5649 | 66 if [ 0$KEEP -gt 0 ]; then |
pascal@5649 | 67 [ $KEEP -gt 1 ] && rotate $KEEP gz |
pascal@5677 | 68 for i in *.gz ; do |
pascal@5677 | 69 [ -e $i ] && mv -f $i $i.0 |
pascal@5677 | 70 done |
pascal@5649 | 71 fi |
pascal@5649 | 72 |
pascal@7324 | 73 echo "Local backup for $(hostname) ..." |
pascal@5649 | 74 backup_data |
pascal@5649 | 75 |
pascal@5649 | 76 chown $BACKUP_USER * |
pascal@5649 | 77 chmod 700 * |
pascal@5649 | 78 |
pascal@5677 | 79 [ -n "$REMOTE_USER" ] && for i in $(cd .. ; ls); do |
pascal@7324 | 80 [ $i == $(hostname) -o $i.slitaz.org == $(hostname) ] && continue |
pascal@7324 | 81 echo "Get backups from $i ..." |
pascal@5649 | 82 rsync -aH -e "$SSH" --bwlimit=50 $REMOTE_USER@$i.slitaz.org:/home/backups/$i/. ../$i/. |
pascal@5649 | 83 done |