[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Move Command Feature
From: |
Assaf Gordon |
Subject: |
Re: Move Command Feature |
Date: |
Fri, 05 Apr 2013 14:24:51 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120510 Icedove/10.0.4 |
Hello Michael,
Michael Boldischar wrote, On 04/05/2013 01:56 PM:
>
> My first attempt with rsync resulted in the same problem I have when there
> are errors using the "mv" command:
> $ mkdir a b
> $ touch a/1.txt a/2.txt
> $ chmod 000 a/2.txt
> $rsync -r --remove-source-files a/ b/
> rsync: send_files failed to open "/tmp/test/a/2.txt": Permission denied (13)
> rsync error: some files/attrs were not transferred (see previous errors)
> (code 23) at main.c(1070) [sender=3.0.8]
> $ ls b
> 1.txt
> $ ls a
> 2.txt
>
> The "a" directory was partially moved. This is no big deal with a small set
> of files, but a large set becomes a headache.
There's one advantage to "rsync" - it can continue copying files from where it
left off.
That is - if something went wrong and it stopped, you can easily resume with
exactly the same command line.
Example:
# Your scenario
$ mkdir a b
$ touch a/1.txt a/2.txt
$ chmod 000 a/2.txt
$ rsync -r --remove-source-files a/ b/
rsync: send_files failed to open "/tmp/test/a/2.txt": Permission denied (13)
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1070) [sender=3.0.8]
# Rsync stopped, some files are moved to "b", some are still in "a".
# now, "fix" the problem, and re-run "rsync"
$ chmod 444 a/2.txt
$ rsync -r --remove-source-files a/ b/
# the result: all files moved from "a" to "b".
$ ls a
$ ls b
1.txt 2.txt
Running "rsync" can be done repeatedly, until all files have been moved.
Large files or small files, many files or few files - rsync will handle them
all just fine.
But regarding your question:
>
> On 04/05/2013 11:23 AM, Michael Boldischar wrote:
> > Hello,
> >
> > This is a suggestion for a new feature in the "mv" command. This
> feature
> > applies to moving directories. If a user moves a directory with a lot
> of
> > files and encounters an error, it can often leave the source directory
> in a
> > partially moved state. It makes it hard to redo the operation because
> the
> > source directory has changed.
> >
There is a subtle difference between "keeping the source directory intact until
the move is complete" and "being able to resume/redo the move".
If you just want to be able to resume an interrupted move, "rsync" can do it.
You'll have to accept that until "rsync" complete successfully, some files are
moved and some aren't (what you called "partial state").
But when "rsync" is complete (perhaps after running it multiple times) - the
move is complete and there's no "partial state".
If you insist of keeping a full copy of the source directory until the entire
move is complete, then something like:
rsync -r a/ b/ && rm -r a/
would do the trick - "a/" will not be modified until the copy is completed.
If you're moving files on the same filesystem and can use hardlinks to avoid
unnecessary copies, then "rsync" have flags for that as well.
Hope this helps,
-gordon