Linux下架设rsync服务器


In: 网络服务 | Author: easylife | 115 views

9 2010

  七、一些可借鉴的脚本

  这里这些脚本都是rsync网站上的例子:

  1、每隔七天将数据往中心服务器做增量备份

  #!/bin/sh

  # This script does personal backups to a rsync backup server. You will end up
  # with a 7 day rotating incremental backup. The incrementals will go
  # into subdirectories named after the day of the week, and the current
  # full backup goes into a directory called "current"
  # tridge@linuxcare.com

  # directory to backup
  BDIR=/home/$USER

  # excludes file – this contains a wildcard pattern per line of files to exclude
  EXCLUDES=$HOME/cron/excludes

  # the name of the backup machine
  BSERVER=owl

  # your password on the backup server
  export RSYNC_PASSWORD=XXXXXX

  ########################################################################

  BACKUPDIR=`date +%A`
  OPTS="–force –ignore-errors –delete-excluded –exclude-from=$EXCLUDES
      –delete –backup –backup-dir=/$BACKUPDIR -a"

  export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

  # the following line clears the last weeks incremental directory
  [ -d $HOME/emptydir ] || mkdir $HOME/emptydir
  rsync –delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
  rmdir $HOME/emptydir

  # now the actual transfer
  rsync $OPTS $BDIR $BSERVER::$USER/current

  2、备份至一个空闲的硬盘

  #!/bin/sh

  export PATH=/usr/local/bin:/usr/bin:/bin

  LIST="rootfs usr data data2"

  for d in $LIST; do
    mount /backup/$d
    rsync -ax –exclude fstab –delete /$d/ /backup/$d/
    umount /backup/$d
  done

  DAY=`date "+%A"`
   
  rsync -a –delete /usr/local/apache /data2/backups/$DAY
  rsync -a –delete /data/solid /data2/backups/$DAY

  3、对vger.rutgers.edu的cvs树进行镜像

  #!/bin/bash

  cd /var/www/cvs/vger/
  PATH=/usr/local/bin:/usr/freeware/bin:/usr/bin:/bin

  RUN=`lps x | grep rsync | grep -v grep | wc -l`
  if [ "$RUN" -gt 0 ]; then
    echo already running
    exit 1
  fi

  rsync -az vger.rutgers.edu::cvs/CVSROOT/ChangeLog $HOME/ChangeLog

  sum1=`sum $HOME/ChangeLog`
  sum2=`sum /var/www/cvs/vger/CVSROOT/ChangeLog`

  if [ "$sum1" = "$sum2" ]; then
    echo nothing to do
    exit 0
  fi

  rsync -az –delete –force vger.rutgers.edu::cvs/ /var/www/cvs/vger/
  exit 0

  4、利用find的一种巧妙方式

  rsync -avR remote:'`find /home -name "*.[ch]"`' /tmp/

  可以用这种方法列出需要备份的文件列表——这种方法似乎比较少人用到。
   
  八、参考资料

  http://www.linuxsir.org/main/?q=node/256
  http://www.backup.idv.tw/good_doc/linux/backup/20030726/rsync.htm
  http://blog.chinaunix.net/u2/79180/showart.php?id=1859608
  http://www.xfocus.net/articles/200107/214.html

页面: 1 2 3 4 5

Comment Form

About this blog

这是一个Linux/Unix技术交流群成员交流知识、分享技巧的群交流平台。如果你有好的资料愿意分享,但暂时不是本群成员,可以点击顶部导航Add Group按钮进行入群测试。欢迎你的加入!

Photostream

    理解Linux的处理器负载均值

    Unix和Unix-like的发展历史

  • Vincent: 这个问题我也遇到了,很久都没解决,编译了N多次,感谢啊~~~(内牛满面) [...]
  • 天空之城: 恩,是这样的。iptables的问题遇到过吗?我在头疼这个问题。 [...]
  • ky: 楼上的太恶劣了。。。 [...]
  • fh.cn: ....再板凳 [...]
  • fh.cn: 呵呵、板凳 [...]
  • yoyojacky: well done! Mike, it’s unbeliveable! wish this site a fabulous 2010… [...]
  • init4: 这个问题我也遇到过 [...]
  • 19466846: 这个问题在debian的bug report中已经有过讨论: Upgrading kernel to 2.6.25.9, the LVM utilities could not find any Volume Groups. This is due to the new /sys/block layout and the LVM sysf [...]

无觅相关文章插件,快速提升流量