Recent Changes - Search:

Research


edit SideBar


DokuWikiBackup

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 <paul@thewall.de>

Quite some commands are not working on the linksys box, a.o. seq, 'bz2 and tar --exclude'' <code bash>

  1. 1 -> path
  2. 2 -> name
  3. 3 -> number of backups (DataBackups = 8)
  4. seq not supported on linksys box ??

rotateDir() {

   i=$3
   let "i=$i-1"   # DataBackups-1
   while [ $i -gt "0" ]
   do
      echo $i
      if [ -f "$1/$2.$i.tar.gz" ]
      then
         let "ii=$i+1"
         echo "$1/$2.$i.tar.gz" "$1/$2.$ii.tar.gz"    # original: mv
      fi
      let "i=$i-1"
    done

}

  1. test procedure

echo "testing procedure" rotateDir "/tmp" "data" $DAILY_DATA_BACKUPS </code> And here is the backup code <code bash>

  1. !/bin/sh
  2. $Id: dw-backup.sh 328 2004-12-22 13:15:20Z dp $
  3. config

TEST="1" # test variable, only echo output WIKIPATH="/opt/www/www2" # path to your wiki BACKUPPATH="/home/trinejos/9-BackupWiki" # where do you save the backups? DAILY_DATA_BACKUPS="8" # keep this amount data backups DAILY_MEDIA_BACKUPS="3" # and media backups

  1. no more config
  2. creates $1, if not existant

checkDir() {

	if [ ! -d "${BACKUPPATH}/$1" ]
	then
		mkdir -p "${BACKUPPATH}/$1"
	fi

}

  1. 1 -> path
  2. 2 -> name
  3. 3 -> number of backups (DataBackups = 8)
  4. seq not supported on linksys box ??
  5. 1 -> path
  6. 2 -> name
  7. 3 -> number of backups (DataBackups = 8)
  8. seq not supported on linksys box ??

rotateDir() {

   i=$3
   let "i=$i-1"   # DataBackups-1
   while [ $i -gt "0" ]
   do
      # echo $i
      if [ -f "$1/$2.$i.tar.gz" ]
      then
         let "ii=$i+1"
         mv "$1/$2.$i.tar.gz" "$1/$2.$ii.tar.gz"    # for testing, use echo
      fi
      let "i=$i-1"
    done

}

  1. test procedure
  2. rotateDir "/tmp" "data" "5"
  3. make sure everything exists

checkDir "data" checkDir "data/archive" checkDir "data/daily"

checkDir "media" checkDir "media/archive" checkDir "media/daily"

  1. first step: rotate daily.

rotateDir "${BACKUPPATH}/data/daily" "data" "$DAILY_DATA_BACKUPS" rotateDir "${BACKUPPATH}/media/daily" "media" "$DAILY_MEDIA_BACKUPS"

  1. then create our backup
  2. --exclude is not accepted for Linksys NSLU2 box, any alternative?
  3. orig: tar --exclude=".*" -cjf "/tmp/data.1.tar.bz2" -C "${WIKIPATH}" "data"
  4. orig: tar --exclude=".*" -cjf "/tmp/media.1.tar.bz2" -C "${WIKIPATH}" "media"

tar -czf "/tmp/data.1.tar.gz" -C "${WIKIPATH}" "data" tar -czf "/tmp/media.1.tar.gz" -C "${WIKIPATH}" "media"

  1. create an archive backup?
  2. orig: if [ `date +%d` !!! "01" ]
  3. testline, execute for every day

if [ `date +%d` -eq "11" ] then

	cp "/tmp/data.1.tar.gz" "${BACKUPPATH}/data/archive/data-"`date +d-%Y`".tar.gz"
	cp "/tmp/media.1.tar.gz" "${BACKUPPATH}/media/archive/media-"`date +d-%Y`".tar.gz"

fi

  1. add them to daily.

mv "/tmp/data.1.tar.gz" "${BACKUPPATH}/data/daily" mv "/tmp/media.1.tar.gz" "${BACKUPPATH}/media/daily" </code>

/etc/crontab entry !!

<code>

  1. cat /etc/crontab

SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin MAILTO="trinejos@online.no" HOME=/

  1. ---------- ---------- Default is Empty ---------- ---------- #

0 0-23/8 * * * root /usr/sbin/CheckDiskFull &>/dev/null 0 0 * * * root /usr/sbin/WatchDog &>/dev/null 1 * * * * root /opt/bin/ntpclient -s -l -h 0.pool.ntp.org > /opt/var/log/ntp.log && hwclock --systohc --localtimea 04 4 * * * root /opt/bin/test-backup &> /dev/null

  1. 05 4 * * * root /opt/bin/backup-wiki 1>>/opt/var/log/wiki-out.log 2>>/opt/var/log/wiki-backup.log # did not work

</code>

script: test-backup !!

<code>

  1. cat /opt/bin/test-backup
  2. !/bin/sh
  3. config

echo "starting backup-wiki, calling the file" /opt/bin/backup-wiki 1>>/opt/var/log/wiki-out.log 2>/opt/var/log/wiki-backup.log </code>

Edit - History - Print - Recent Changes - Search
Page last modified on May 31, 2005, at 11:22 PM EST