
私のスクリプト--delete --delete-after
には、basedirなどのディレクトリにrsync
名前が付いたディレクトリがあります。スクリプトを実行するたびにディレクトリを削除したくありません。どのようなオプションが私に役立つでしょうか?
releases
rsync
releases
rsync
修正する:
私のスクリプトrsync
:
#/bin/dash
fatal() {
echo "$1"
exit 1
}
warn() {
echo "$1"
}
# Find a source mirror near you which supports rsync on
# https://launchpad.net/ubuntu/+archivemirrors
# rsync://<iso-country-code>.rsync.archive.ubuntu.com/ubuntu should always work
RSYNCSOURCE=rsync://archive.ubuntu.com/ubuntu
# Define where you want the mirror-data to be on your mirror
BASEDIR=/home/ubuntu/
if [ ! -d ${BASEDIR} ]; then
warn "${BASEDIR} does not exist yet, trying to create it..."
mkdir -p ${BASEDIR} || fatal "Creation of ${BASEDIR} failed."
fi
rsync --recursive --times --links --safe-links --hard-links \
--stats \
--exclude "Packages*" --exclude "Sources*" \
--exclude "Release*" --exclude "InRelease" --exclude "releases" \
${RSYNCSOURCE} ${BASEDIR} || fatal "First stage of sync failed."
rsync --recursive --times --links --safe-links --hard-links \
--stats --delete --delete-after --exclude "releases" \
${RSYNCSOURCE} ${BASEDIR} || fatal "Second stage of sync failed."
date -u > ${BASEDIR}/project/trace/$(hostname -f)
chown 997:997 /home/ubuntu/* -R
答え1
これらの--delete
オプションは、送信側ではなく受信側にのみ存在するファイルに関連しています。あなたの質問では明確ではありませんが、Mohsen
送信側に指定されたディレクトリがあり、そのディレクトリが同期しているようです。Mohsen
同期操作のルートディレクトリの場合は、ソースパスを/
追加してこれを回避できます。rsync me@remote/path/there/ local/path/here
コンテンツは同期されますが、there
ディレクトリはhere
作成されませんthere
。 OTOHがMohsen
サブディレクトリの場合 - オプションを使用してそのディレクトリ(およびサブツリー)を除外できます--exclude
。
答え2
あなたのスクリプトはあなたが要求したものと正確に一致しなければなりません。つまり、releases
完全に無視してターゲットから削除しないでください。
除外をよりよく定義し、--exclude '/releases/'
それをトランスポートの最上位レベルにリンクし、ディレクトリとして定義できますが、ここではそうではありません。