LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 705|回复: 3

帮我解释这个脚本

[复制链接]
发表于 2004-5-28 09:23:37 | 显示全部楼层 |阅读模式
帮我解释一下这个脚本,主要是最后面几行,谢谢先。

[PHP]
#!/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




[/PHP]
发表于 2004-5-28 12:03:54 | 显示全部楼层
熟悉rsync用法的话,这段脚本就不难理解~
 楼主| 发表于 2004-5-30 14:19:07 | 显示全部楼层
大致懂,但具体意思还一知半解。

请斑竹大哥解释一下。
发表于 2004-5-30 15:17:11 | 显示全部楼层
大致解释:
上述语句定义了脚本需要的必要变量,以便下面引用
#定义一个变量名,BACKUPDIR,是用当前时间作为备份目录名的
BACKUPDIR=`date +%A`
#定义一个变量名,OPTS,这是个rsycn的选项
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
      --delete --backup --backup-dir=/$BACKUPDIR -a"
#导出PATH变量当当前的shell环境
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin

# the following line clears the last weeks incremental directory
#清除最近的增量目录
#如果$HOME/emptydir目录存在的话,执行rsync命令,否则,创建$HOME/emptydir目录
#并执行rsync,||是shell的逻辑或,这个不难理解
[ -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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表