一時ファイルを残さずにrsyncを停止する

一時ファイルを残さずにrsyncを停止する

次のコマンドを使用して、ディレクトリからディレクトリにファイルをコピーしますABrsync

$ rsync -a --backup --suffix=.$(date +"%Y%m%d%H%M%S")  A/ B/

filename呼び出されたファイルは、転送中にAフォームから一時的に呼び出されます。つまり、転送が完了するまで名前にランダムな文字を追加します。.filename.9TcfsaBrsync

転送中に+をrsync使用して中断すると、一時Ctrlファイルはに残ります。私のコマンドはファイルを削除しないので、すべての割り込みは別の一時ファイルを残します。これは迷惑なゴミに変わった。cfilename.filename.9TcfsaBrsyncBrsyncB

rsync一時ファイルを停止して削除できますか?

修正する: 他の人は上記の問題を経験していないようで、私のコンピュータに現れる現象を示すために出力を含むスクリプトを提供しました。

スクリプトrsynctest.sh:

#/!bin/bash
mkdir -p A
mkdir -p B
echo "Creating a 1 GB file in A..."
dd if=/dev/zero of=A/bigfile bs=1M count=1000 >& /dev/null
echo "Now press CTRL-C to interrupt rsync."
rsync -a --backup --suffix=.$(date +"%Y%m%d%H%M%S")  A/ B/

スクリプトを2回実行すると出力されます。

$ ./rsynctest.sh 
Creating a 1 GB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.0]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at io.c(521) [generator=3.1.0]
$ ./rsynctest.sh 
Creating a 1 GB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.0]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at io.c(521) [generator=3.1.0]
$ ls -a B
.  ..  .bigfile.KvDV0T  .bigfile.MbalWJ
$

最後lsのコマンドにはB2つの一時ファイルが含まれているようです。

ベストアンサー1

A:これはrsync3.1.0のバグです。

これはから来たものです3.1.1.リリースノート

中断時に部分転送一時ファイルが削除されない問題を修正しました(そしてrsyncが部分ファイルを保存していません)。

rsync.

昔のこと

私は私のシステムでこれをテストしました。

tony@trinity:~$ uname -a
Linux trinity 3.2.0-4-686-pae #1 SMP Debian 3.2.73-2+deb7u2 i686 GNU/Linux
tony@trinity:~$ cat /etc/debian_version
7.10
tony@trinity:~$ rsync --version
rsync  version 3.0.9  protocol version 30

したがって、まったく同じバージョンではありませんが、rsync同じメジャーバージョンです。

Ctrl期待通りに+をクリックするとcクリーンrsyncアップが行われ、一時ファイルは残りません。

A/とを作成し、いくつかのファイルを入力し、B/一度実行して 。それから走り、再び走った。A/rsyncB/touchA/rsync

処理中のファイルを表示できるように1つを追加しましたが、-v-vがない場合、動作は同じです。

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S")  A/ B/
sending incremental file list
archives/floppies.tgz
archives/fromx1.tgz
archives/homestuff.tgz
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(549) [sender=3.0.9]
tony@trinity:~$ cd B
tony@trinity:~/B$ cd archives/
tony@trinity:~/B/archives$ ls -l
total 78620
-rw-r----- 1 tony tony  7031885 Apr 15 14:44 floppies.tgz
-rw-r----- 1 tony tony  7031885 Apr 15 14:37 floppies.tgz.20160415144513
-rw-r--r-- 1 tony tony 13959801 Apr 15 14:44 fromx1.tgz
-rw-r--r-- 1 tony tony 13959801 Apr 15 14:37 fromx1.tgz.20160415144513
-rw-r--r-- 1 tony tony 26136212 Apr 15 14:37 homestuff.tgz
-rw-r----- 1 tony tony  5727535 Apr 15 14:37 legacy-x1-scripts.tgz
-rw-r----- 1 tony tony  6636756 Apr 15 14:37 olddos.tgz
drwxr-xr-x 2 tony tony     4096 Apr 15 14:44 oldsites
drwxr-xr-x 2 tony tony     4096 Apr 15 14:44 temp

一時ファイルがありません。だから、おそらく内容が変わっていないので、一時rsyncファイルを作成する必要はないようです。

今回は大容量ファイルを持ってきましたA\

tony@trinity:~$ ls -l A/
total 561528
-rw-r--r-- 1 tony tony 574996664 Apr 15 14:52 bigfile.tgz

私は同期しますB/

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S") A/ B/
sending incremental file list
bigfile.tgz

sent 575066959 bytes  received 31 bytes  10953656.95 bytes/sec
total size is 574996664  speedup is 1.00

その後、bigfile.tgz全く別のものと交換してください。

tony@trinity:~$ ls -l A/
total 572576
-rw-r--r-- 1 tony tony 586311642 Apr 15 14:57 bigfile.tgz

これは、同じファイルサイズを構成するためにコピーされ続ける別のtgzアーカイブです。

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S") A/ B/
sending incremental file list
bigfile.tgz
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(549) [sender=3.0.9]
tony@trinity:~$ ls -l B/
total 561528
-rw-r--r-- 1 tony tony 574996664 Apr 15 14:52 bigfile.tgz

一時ファイルがありません。

再起動してください。新しいファイルです。

tony@trinity:~$ ls -l A/
total 433908
-rw-r--r-- 1 tony tony 444315604 Apr 15 15:02 bigfile.tgz

同期先B/

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S")  A/ B/
sending incremental file list
bigfile.tgz

sent 444369947 bytes  received 31 bytes  32916294.67 bytes/sec
total size is 444315604  speedup is 1.00

今、A/bigfile.tgz別のコンテンツで作り直してください。

tony@trinity:~$ ls -l A/
total 545312
-rw-r--r-- 1 tony tony 558392040 Apr 15 15:04 bigfile.tgz

今回は、を実行rsyncして--partial変更を確認してください。このスイッチは通常、rsyncいくつかのファイルを消去するのではなく強制的に残します。

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S") --partial A/ B/
sending incremental file list
bigfile.tgz
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(549) [sender=3.0.9]
tony@trinity:~$ ls -l B/
total 464596
-rw-r--r-- 1 tony tony  31424512 Jan  1  1970 bigfile.tgz
-rw-r--r-- 1 tony tony 444315604 Apr 15 15:02 bigfile.tgz.20160415150558

今回はrsync一時ファイル(bigfile.tgzと呼ばれる)を作成し、古いファイルに新しい拡張子を付けました。

編集:一連のテストを再利用しますls -la

tony@trinity:~$ ls -la A/
total 510488
drwxr-xr-x  2 tony tony      4096 Apr 15 15:22 .
drwxr-xr-x 89 tony tony      4096 Apr 15 15:12 ..
-rw-r--r--  1 tony tony 522724240 Apr 15 15:22 bigfile.tgz

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S") A/ B/
sending incremental file list
bigfile.tgz

sent 522788155 bytes  received 31 bytes  22246305.79 bytes/sec
total size is 522724240  speedup is 1.00

したがってB/、同期です。

tony@trinity:~$ ls -la B/
total 510484
drwxr-xr-x  2 tony tony      4096 Apr 15 15:23 .
drwxr-xr-x 89 tony tony      4096 Apr 15 15:12 ..
-rw-r--r--  1 tony tony 522724240 Apr 15 15:22 bigfile.tgz

交換A/bigfile.tgzして再同期してください。

tony@trinity:~$ ls -la A/
total 545320
drwxr-xr-x  2 tony tony      4096 Apr 15 15:24 .
drwxr-xr-x 89 tony tony      4096 Apr 15 15:12 ..
-rw-r--r--  1 tony tony 558392040 Apr 15 15:24 bigfile.tgz

tony@trinity:~$ rsync -v -a --backup --suffix=.$(date +"%Y%m%d%H%M%S") A/ B/
sending incremental file list
bigfile.tgz
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(549) [sender=3.0.9]
tony@trinity:~$ ls -la B/
total 510484
drwxr-xr-x  2 tony tony      4096 Apr 15 15:25 .
drwxr-xr-x 89 tony tony      4096 Apr 15 15:12 ..
-rw-r--r--  1 tony tony 522724240 Apr 15 15:22 bigfile.tgz

一時ファイルがありません。

basicを使用して説明した動作を再現することはできませんrsync

あなたのrsyncコマンドが説明と正確に一致し、どこかの他のコマンドのエイリアスが指定されていませんか?

修正する:

別のコンピュータでスクリプトを使用してください。

tony@matrix:~$ ./rsynctest.sh
Creating a 500 MB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.1]
rsync: [sender] write error: Broken pipe (32)
tony@matrix:~$ ls -la B/
total 8
drwxr-xr-x  2 tony users 4096 Apr 15 19:54 .
drwxr-xr-x 37 tony users 4096 Apr 15 19:54 ..
tony@matrix:~$ ./rsynctest.sh
Creating a 500 MB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.1]
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at io.c(504) [generator=3.1.1]
tony@matrix:~$ ls -la B/
total 8
drwxr-xr-x  2 tony users 4096 Apr 15 19:54 .
drwxr-xr-x 37 tony users 4096 Apr 15 19:54 ..

tony@matrix:~$ uname -a
Linux matrix 3.12.46-guest-39-a97a54c-x86_64 #4 SMP Mon Aug 10 11:59:25 UTC 2015 x86_64 GNU/Linux
tony@matrix:~$ cat /etc/debian_version
8.3
tony@matrix:~$ rsync --version
rsync  version 3.1.1  protocol version 31

今回は純粋なDebianの代わりにUbuntuという別のマシンです。

tony@neo:/$ lsb_release -r
Release:        15.10
tony@neo:/$ uname -a
Linux neo 4.2.0-34-generic #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
tony@neo:/$ rsync --version
rsync  version 3.1.1  protocol version 31
Copyright (C) 1996-2014 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes, prealloc

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.

tony@neo:~$ vi rsynctest.sh
tony@neo:~$ chmod 755 rsynctest.sh
tony@neo:~$ ./rsynctest.sh
Creating a 1 GB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.1]
rsync: [receiver] write error: Broken pipe (32)
rsync: [sender] write error: Broken pipe (32)
tony@neo:~$ ls -la B/
total 8
drwxrwxr-x  2 tony tony 4096 Apr 15 20:09 .
drwxr-xr-x 20 tony tony 4096 Apr 15 20:09 ..
tony@neo:~$ ./rsynctest.sh
Creating a 1 GB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.1]
tony@neo:~$ ls -la B/
total 8
drwxrwxr-x  2 tony tony 4096 Apr 15 20:10 .
drwxr-xr-x 20 tony tony 4096 Apr 15 20:09 ..
tony@neo:~$ ./rsynctest.sh
Creating a 1 GB file in A...
Now press CTRL-C to interrupt rsync.
^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(632) [sender=3.1.1]
tony@neo:~$ ls -la B/
total 8
drwxrwxr-x  2 tony tony 4096 Apr 15 20:10 .
drwxr-xr-x 20 tony tony 4096 Apr 15 20:09 ..

おすすめ記事