我不懂 Linux,更不懂编程,所以请原谅我的无知。
我有这个脚本,希望有人能向我解释其内部原理。
我理解的语法是:
30 1 * * * /root/dobackup.daily /shared/svnrepos WOWSERVER /shared/backup/svnrepos
在 1:30 将服务器上的 /shared/svnrepos 进行 rysnc 备份到远程 WOWSERVER,并将其放在 WOWSERVER 上的 /shared/backup/snvrepos 中。
但是,我不理解脚本中的“选项/变量/等”,希望有人可以为我解释一下。
脚本如下:
#!/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"
# [email protected]
# directory to backup
if [ $# != 3 ]; then
echo "Syntax is \"dobackup.daily {LocalDir} {RemoteServer} {RemoteDir}\""
exit
fi
#RDIR=/shared/backup/CADData
RDIR=$3
# excludes file - this contains a wildcard pattern per line of files to exclude
EXCLUDES=
# the name of the backup machine
#RSERVER=TESTSERVER
RSERVER=$2
#LDIR=/shared/CADData
LDIR=$1
# your password on the backup server
#export RSYNC_PASSWORD=XXXXXX
########################################################################
TODAY=`date +%A`
YESTERDAY=`date --date=yesterday +%A`
#TODAY=test3
#YESTERDAY=Monday
OPTS="--link-dest=../$YESTERDAY --timeout=999 -aAz"
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 -aAz -e 'ssh -c blowfish -i /root/.ssh/backup -ax -o ClearAllForwardings=yes' $HOME/emptydir/ $RSERVER:$RDIR/$BACKUPDIR/
# rmdir $HOME/emptydir
# now the actual transfer
rsync $OPTS -e 'ssh -c blowfish -i /root/.ssh/4to5 -ax -o ClearAllForwardings=yes' $LDIR/ $RSERVER:$RDIR/$TODAY/
答案1
- RDIR——远程(备份)目录
- $3——第三个命令行选项(例如
command option1 option2 option3
) - EXCLUDES – 要排除的文件名
- RSERVER - 要备份到的远程服务器
- $2——第二个命令行选项(例如
command option1 option2
) - LDIR——要备份的本地目录
- $1 - 第一个命令行选项(例如
command option1 option2
) date
TODAY-从命令中获取日期date
昨天-从命令中获取昨天的日期- OPTS - rsync 的命令行选项(勾选
man rsync
) - 导出 PATH - 确保 PATH 环境变量包含 rsync 的可能位置
- $HOME - 运行脚本的用户的主文件夹 (/home/username)