Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.linux > #54398 > unrolled thread

Move file with directory structure

Started byLeslie Rhorer <lrhorer@mygrande.net>
First post2019-03-13 05:53 -0700
Last post2019-03-13 19:07 -0700
Articles 19 — 9 participants

Back to article view | Back to alt.os.linux


Contents

  Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 05:53 -0700
    Re: Move file with directory structure gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-13 13:33 +0000
    Re: Move file with directory structure Joe Beanfish <joebeanfish@nospam.duh> - 2019-03-13 13:47 +0000
    Re: Move file with directory structure Fenris <fenris@invalid.invalid> - 2019-03-13 15:02 +0100
    Re: Move file with directory structure marrgol <marrgol@address.invalid> - 2019-03-13 15:18 +0100
      Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:33 -0700
    Re: Move file with directory structure Java Jive <java@evij.com.invalid> - 2019-03-13 14:43 +0000
      Re: Move file with directory structure Chris Elvidge <chris@mshome.net> - 2019-03-13 15:19 +0000
        Re: Move file with directory structure Java Jive <java@evij.com.invalid> - 2019-03-13 16:18 +0000
    Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:27 -0700
      Re: Move file with directory structure gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-13 16:12 +0000
      Re: Move file with directory structure William Unruh <unruh@invalid.ca> - 2019-03-13 21:05 +0000
        Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 19:29 -0700
          Re: Move file with directory structure "Carlos E.R." <robin_listas@es.invalid> - 2019-03-14 14:12 +0100
            Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-14 08:34 -0700
      Re: Move file with directory structure "Carlos E.R." <robin_listas@es.invalid> - 2019-03-14 18:22 +0100
    Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 08:37 -0700
      Re: Move file with directory structure William Unruh <unruh@invalid.ca> - 2019-03-13 21:10 +0000
        Re: Move file with directory structure Leslie Rhorer <lrhorer@mygrande.net> - 2019-03-13 19:07 -0700

#54398 — Move file with directory structure

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 05:53 -0700
SubjectMove file with directory structure
Message-ID<a6ab8a1c-1d99-4ca1-8993-ac9bbccfe5af@googlegroups.com>
I have a little issue, and I am hoping someone here has a simple and elegant solution.  I want to be able to run a BASH script which will prune specific files out of an arbitrary directory by moving the files out of the directory into a holding directory reproducing the entire source directory tree.

So, for example, say I have a file:

/Dir1/Dir2/Dir3.../DirN/File to be moved

There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to move the "File to be moved" file, not the entire directory.

I have a directory in place named /Scrutiny/.  I want to move "File to be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like

mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/

Then the file wil just be dumped into the /Scrutiny directory without the tree structure.  I could parse the filespec for its directory structure, issue a mkdir command, and then move the file to the new structure, but is there a more efficient way?

[toc] | [next] | [standalone]


#54399

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2019-03-13 13:33 +0000
Message-ID<q6b0rs$13f$1@news.xmission.com>
In reply to#54398
In article <a6ab8a1c-1d99-4ca1-8993-ac9bbccfe5af@googlegroups.com>,
Leslie Rhorer  <lrhorer@mygrande.net> wrote:
>I have a little issue, and I am hoping someone here has a simple and elegant
>solution.  I want to be able to run a BASH script which will prune specific files
>out of an arbitrary directory by moving the files out of the directory into a
>holding directory reproducing the entire source directory tree.
>
>So, for example, say I have a file:
>
>/Dir1/Dir2/Dir3.../DirN/File to be moved
>
>There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to
>move the "File to be moved" file, not the entire directory.
>
>I have a directory in place named /Scrutiny/.  I want to move "File to be moved"
>to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general
>/Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like
>
>mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
>
>Then the file wil just be dumped into the /Scrutiny directory without the tree
>structure.  I could parse the filespec for its directory structure, issue a mkdir
>command, and then move the file to the new structure, but is there a more
>efficient way?

tar is your friend.

$ cd Scrutiny
$ tar c --remove-files "/Dir1/Dir2/Dir3.../DirN/File to be moved" | tar xv
$

Notes:
    1) There are also ways to do it with cpio - they are similar.  I've
	used cpio in the past, but nowadays, I am used to using tar.
    2) This is simple, but other posters will complain that it does an
	unnecessary copy when a move would be "more efficient".  This is
	unlikely to matter unless the file is very large and would be moot
	anyway if the two directories on not on the same file system.
    3) Other posters will be along any minute now with complicated "find"
	command lines.  I'd tend to ignore those posts.

-- 
You are a dreadful man, Kenny, for all your ways are the ways of death.
    - Rick C Hodgin -

(P.S. -> https://www.youtube.com/watch?v=sMmTkKz60W8)

[toc] | [prev] | [next] | [standalone]


#54400

FromJoe Beanfish <joebeanfish@nospam.duh>
Date2019-03-13 13:47 +0000
Message-ID<q6b1kq$uap$1@dont-email.me>
In reply to#54398
On Wed, 13 Mar 2019 05:53:07 -0700, Leslie Rhorer wrote:

> I have a little issue, and I am hoping someone here has a simple and
> elegant solution.  I want to be able to run a BASH script which will
> prune specific files out of an arbitrary directory by moving the files
> out of the directory into a holding directory reproducing the entire
> source directory tree.
> 
> So, for example, say I have a file:
> 
> /Dir1/Dir2/Dir3.../DirN/File to be moved
> 
> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I
> only want to move the "File to be moved" file, not the entire directory.
> 
> I have a directory in place named /Scrutiny/.  I want to move "File to
> be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general 
>/Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command
> like
> 
> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
> 
> Then the file wil just be dumped into the /Scrutiny directory without
> the tree structure.  I could parse the filespec for its directory
> structure, issue a mkdir command, and then move the file to the new
> structure, but is there a more efficient way?

Create a file with a list of files to move with their full paths, one per 
line.

Copy the files to scrutiny dir
   cpio -pvdm /Scrutiny <listfile
Delete the files from original dir
   xargs rm -f <listfile

[toc] | [prev] | [next] | [standalone]


#54402

FromFenris <fenris@invalid.invalid>
Date2019-03-13 15:02 +0100
Message-ID<Pine.NEB.4.64.1903131459280.5651@miku.sdf.org>
In reply to#54398

On Wed, 13 Mar 2019, Leslie Rhorer wrote:

> Date: Wed, 13 Mar 2019 05:53:07 -0700 (PDT)
> From: Leslie Rhorer <lrhorer@mygrande.net>
> Newsgroups: alt.os.linux
> Subject: Move file with directory structure
> 
> I have a little issue, and I am hoping someone here has a simple and elegant solution.  I want to be able to run a BASH script which will prune specific files out of an arbitrary directory by moving the files out of the directory into a holding directory reproducing the entire source directory tree.
>
> So, for example, say I have a file:
>
> /Dir1/Dir2/Dir3.../DirN/File to be moved
>
> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to move the "File to be moved" file, not the entire directory.
>
> I have a directory in place named /Scrutiny/.  I want to move "File to be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like
>
> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
>
> Then the file wil just be dumped into the /Scrutiny directory without the tree structure.  I could parse the filespec for its directory structure, issue a mkdir command, and then move the file to the new structure, but is there a more efficient way?

I think rsync could do it, something like:
rsync "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny

Note: no trailing / on receiver is important, ie. not /Scrutiny/ but 
rather /Scrutiny

[toc] | [prev] | [next] | [standalone]


#54403

Frommarrgol <marrgol@address.invalid>
Date2019-03-13 15:18 +0100
Message-ID<5c89114b$0$482$65785112@news.neostrada.pl>
In reply to#54398
On 2019-03-13 at 13:53, Leslie Rhorer wrote:
> I have a little issue, and I am hoping someone here has a simple and elegant solution.  I want to be able to run a BASH script which will prune specific files out of an arbitrary directory by moving the files out of the directory into a holding directory reproducing the entire source directory tree.
> 
> So, for example, say I have a file:
> 
> /Dir1/Dir2/Dir3.../DirN/File to be moved
> 
> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to move the "File to be moved" file, not the entire directory.
> 
> I have a directory in place named /Scrutiny/.  I want to move "File to be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like
> 
> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
> 
> Then the file wil just be dumped into the /Scrutiny directory without the tree structure.  I could parse the filespec for its directory structure, issue a mkdir command, and then move the file to the new structure, but is there a more efficient way?
> 

Not really much of a parsing involved:

FILE="/Dir1/Dir2/Dir3.../DirN/File to be moved"
DEST="/Scrutiny/$(dirname "$FILE")"
mkdir -p "$DEST"
mv "$FILE" "$DEST"


Or, if you don't mind copying the file first:

rsync --relative --remove-source-files "/Dir1/Dir2/Dir3.../DirN/File to
be moved" /Scrutiny/


-- 
mrg

[toc] | [prev] | [next] | [standalone]


#54408

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 08:33 -0700
Message-ID<8f759d46-9b7a-44de-ba20-67abc20c01d6@googlegroups.com>
In reply to#54403
On Wednesday, March 13, 2019 at 9:18:52 AM UTC-5, marrgol wrote:
> Not really much of a parsing involved:
> 
> FILE="/Dir1/Dir2/Dir3.../DirN/File to be moved"
> DEST="/Scrutiny/$(dirname "$FILE")"
> mkdir -p "$DEST"
> mv "$FILE" "$DEST"

Actually, I tried that, but it doesn't work.  It works fine at the command prompt, but gives me permission errors when executed from within the script.  'Truly weird, since the script is running as root.

> Or, if you don't mind copying the file first:

No, that's out of the question.  See above.

[toc] | [prev] | [next] | [standalone]


#54404

FromJava Jive <java@evij.com.invalid>
Date2019-03-13 14:43 +0000
Message-ID<q6b4v6$1dic$1@gioia.aioe.org>
In reply to#54398
On 13/03/2019 12:53, Leslie Rhorer wrote:
> I have a little issue, and I am hoping someone here has a simple and elegant solution.  I want to be able to run a BASH script which will prune specific files out of an arbitrary directory by moving the files out of the directory into a holding directory reproducing the entire source directory tree.
> 
> So, for example, say I have a file:
> 
> /Dir1/Dir2/Dir3.../DirN/File to be moved
> 
> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I only want to move the "File to be moved" file, not the entire directory.
> 
> I have a directory in place named /Scrutiny/.  I want to move "File to be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command like
> 
> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
> 
> Then the file wil just be dumped into the /Scrutiny directory without the tree structure.  I could parse the filespec for its directory structure, issue a mkdir command, and then move the file to the new structure, but is there a more efficient way?

I can't comment on the other suggestions because I haven't tried them.

You'd've thought that this would be possible with rsync, but I've not 
been able to make it work.

Note the following failed examples were tested on a Zyxel NSA221 NAS, as 
being the only Linux machines that I have powered up at the moment, a 
fuller Linux distro might behave better.

Note also that the -n option means 'show what will happen but don't 
actually do it'  -  naturally you'd remove this once you were satisfied 
that the command is going to do exactly what you want.

Note also that the trailing slash in the source designation is required 
to make an rsync command work properly, by which I mean in the way that 
might be expected, so I put one also at the end of the destination, for 
conformity's sake.

One might have hoped that something like the following should work, but 
it doesn't ...

rsync -an --exclude="*" --include="*.not" $SOURCE/ $DEST/

... the problem being that once the --exclude="*" option has ruled out 
everything, no include option can bring it back in, despite what the 
command-line help implies.  This wouldn't be so bad if the following 
worked, but it doesn't either ...

rsync -an --include="*.not" $SOURCE/ $DEST/

... which just copies everything, not just the *.not files, so is 
exactly the same as not giving an include option at all, making one 
wonder:  "WTF is the point of the include option, when it doesn't seem 
to do anything?!"

The only way I've been able to make this sort of thing work with rsync 
is to write a filter file excluding every goddamned thing I don't want 
to copy, which is an extraordinary chore to have to perform for such a 
*simple* requirement.

Tch!

[toc] | [prev] | [next] | [standalone]


#54405

FromChris Elvidge <chris@mshome.net>
Date2019-03-13 15:19 +0000
Message-ID<q6b71k$t5o$1@dont-email.me>
In reply to#54404
On 13/03/2019 14:43, Java Jive wrote:
> On 13/03/2019 12:53, Leslie Rhorer wrote:
>> I have a little issue, and I am hoping someone here has a simple and 
>> elegant solution.  I want to be able to run a BASH script which will 
>> prune specific files out of an arbitrary directory by moving the files 
>> out of the directory into a holding directory reproducing the entire 
>> source directory tree.
>>
>> So, for example, say I have a file:
>>
>> /Dir1/Dir2/Dir3.../DirN/File to be moved
>>
>> There are a number of other files in /Dir1/Dir2/Dir3.../DirN/, but I 
>> only want to move the "File to be moved" file, not the entire directory.
>>
>> I have a directory in place named /Scrutiny/.  I want to move "File to 
>> be moved" to /Scrutiny/Dir1/Dir2/Dir3.../DirN/, but in general 
>> /Scrutiny/Dir1/Dir2/Dir3.../DirN/ may not exist.  If I issue a command 
>> like
>>
>> mv "/Dir1/Dir2/Dir3.../DirN/File to be moved" /Scrutiny/
>>
>> Then the file wil just be dumped into the /Scrutiny directory without 
>> the tree structure.  I could parse the filespec for its directory 
>> structure, issue a mkdir command, and then move the file to the new 
>> structure, but is there a more efficient way?
> 
> I can't comment on the other suggestions because I haven't tried them.
> 
> You'd've thought that this would be possible with rsync, but I've not 
> been able to make it work.
> 
> Note the following failed examples were tested on a Zyxel NSA221 NAS, as 
> being the only Linux machines that I have powered up at the moment, a 
> fuller Linux distro might behave better.
> 
> Note also that the -n option means 'show what will happen but don't 
> actually do it'  -  naturally you'd remove this once you were satisfied 
> that the command is going to do exactly what you want.
> 
> Note also that the trailing slash in the source designation is required 
> to make an rsync command work properly, by which I mean in the way that 
> might be expected, so I put one also at the end of the destination, for 
> conformity's sake.
> 
> One might have hoped that something like the following should work, but 
> it doesn't ...
> 
> rsync -an --exclude="*" --include="*.not" $SOURCE/ $DEST/
> 
> ... the problem being that once the --exclude="*" option has ruled out 
> everything, no include option can bring it back in, despite what the 
> command-line help implies.  This wouldn't be so bad if the following 
> worked, but it doesn't either ...
> 
> rsync -an --include="*.not" $SOURCE/ $DEST/

try rsync -avn --include=*.not --exclude=* $SOURCE/ $DEST/

> 
> ... which just copies everything, not just the *.not files, so is 
> exactly the same as not giving an include option at all, making one 
> wonder:  "WTF is the point of the include option, when it doesn't seem 
> to do anything?!"
> 
> The only way I've been able to make this sort of thing work with rsync 
> is to write a filter file excluding every goddamned thing I don't want 
> to copy, which is an extraordinary chore to have to perform for such a 
> *simple* requirement.
> 
> Tch!



-- 

Chris Elvidge, England

[toc] | [prev] | [next] | [standalone]


#54411

FromJava Jive <java@evij.com.invalid>
Date2019-03-13 16:18 +0000
Message-ID<q6bag3$87p$1@gioia.aioe.org>
In reply to#54405
On 13/03/2019 15:19, Chris Elvidge wrote:
> 
> try rsync -avn --include=*.not --exclude=* $SOURCE/ $DEST/

Tried that as well, didn't work any differently from exclude first and 
include second.

[toc] | [prev] | [next] | [standalone]


#54407

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 08:27 -0700
Message-ID<24772135-8f6b-4b07-9fdc-c951a99922a6@googlegroups.com>
In reply to#54398
I'm sorry, I should have mentioned these are giant files (up to 40GB), and lots of them.  A copy operation is definitely not practical.  It needs to be a file pointer update, such as a mv, not a copy-and-delete.

[toc] | [prev] | [next] | [standalone]


#54410

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2019-03-13 16:12 +0000
Message-ID<q6ba5v$63v$1@news.xmission.com>
In reply to#54407
In article <24772135-8f6b-4b07-9fdc-c951a99922a6@googlegroups.com>,
Leslie Rhorer  <lrhorer@mygrande.net> wrote:
>I'm sorry, I should have mentioned these are giant files (up to 40GB),
>and lots of them. A copy operation is definitely not practical. It
>needs to be a file pointer update, such as a mv, not a copy-and-delete.
>

This is indeed critical information.

In that case, I would go with the simple:

    dirname=/Scrutiny/${fn%/*}
    mkdir -p $dirname
    mv $fn $dirname

Still pretty straightforward.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

[toc] | [prev] | [next] | [standalone]


#54417

FromWilliam Unruh <unruh@invalid.ca>
Date2019-03-13 21:05 +0000
Message-ID<q6brb2$skl$1@dont-email.me>
In reply to#54407
On 2019-03-13, Leslie Rhorer <lrhorer@mygrande.net> wrote:
> I'm sorry, I should have mentioned these are giant files (up to 40GB), and lots of them.  A copy operation is definitely not practical.  It needs to be a file pointer update, such as a mv, not a copy-and-delete.
>

Not at all sure why you would want to do this, since this implies that
the two are on the same partition.  This cannot be a backup. So why
didn't you put the file into the place you wanted it to be in the first
place. 

But, a) make sure that the directory containing the file is in the
directory you want. Then move the file. 

Note that rsync is a copy, it does not update directory link. So it is
in the "copy and remove" class. 

FILE=DIR1/DIR2/.../DIRN/filename
DIR=dirname $FILE
mkdir -p /CONTAINER/$DIR
mv $FILE /CONTAINER/$FILE

[toc] | [prev] | [next] | [standalone]


#54425

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 19:29 -0700
Message-ID<00f6763e-dbf4-44e6-9e47-d57c6384f437@googlegroups.com>
In reply to#54417
> Not at all sure why you would want to do this, since this implies that
> the two are on the same partition.

What two are on the same partition?  /Backup and /Backup/Scrutiny?  Well, not necessarily, but in this case it is so.  I want to take any files on /Backup (a local RAID array) that are no longer on /RAID and look at them to make sure they indeed no longer need to be on /RAID.

> This cannot be a backup.

No, that happens every morning at 04:30, via rsync, copying every file that does not exist on /Backup or has been modified over to /Backup from /RAID.  That is the backup.

> So why didn't you put the file into the place you wanted it to be in the first
> place.

It was, when the file was created.  It may no longer be so, now. If the files are indeed no longer of any merit, they get deleted by me, manually.  Since they are all collected together, rather than mixed in with tons of perfectly good files, it is easy to see whether the files are no longer of any use.  If one or more are still potentially of use, they will either be copied back over to /RAID, or left where they are until no longer of potential use.

> But, a) make sure that the directory containing the file is in the
> directory you want. Then move the file.

Huh?  If the file were in the directory I want, then there is no reason to move it.

> Note that rsync is a copy, it does not update directory link. So it is
> in the "copy and remove" class. 

I am well aware.  That is why I am not using it.


> FILE=DIR1/DIR2/.../DIRN/filename
> DIR=dirname $FILE
> mkdir -p /CONTAINER/$DIR
> mv $FILE /CONTAINER/$FILE

Yes, that is not the issue, mostly.  It would be nice to collapse that into a single, simple command. It also would be nice if there were a simple way to create /CONTAINER/$FILE, or even better, to eliminate it.  It would e great if there were a command like:

move --prune $FILE $CONTAINER that moves not just the file, but the entire directory structure, as well.  Of course, that is mostly what this script does, so technically it *IS* a `move --prune` command.

[toc] | [prev] | [next] | [standalone]


#54427

From"Carlos E.R." <robin_listas@es.invalid>
Date2019-03-14 14:12 +0100
Message-ID<9i0qlf-e99.ln1@Telcontar.valinor>
In reply to#54425
On 14/03/2019 03.29, Leslie Rhorer wrote:
>> Not at all sure why you would want to do this, since this implies that
>> the two are on the same partition.
> 
> What two are on the same partition?  /Backup and /Backup/Scrutiny?  Well, not necessarily, but in this case it is so. 

They have to be, or move is impossible (no pointer update possible
across partitions). It will be then copy first, delete second.

-- 
Cheers, Carlos.

[toc] | [prev] | [next] | [standalone]


#54428

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-14 08:34 -0700
Message-ID<6de1507f-7dc1-49b8-bae7-d98ebb3b9346@googlegroups.com>
In reply to#54427
On Thursday, March 14, 2019 at 8:12:17 AM UTC-5, Carlos E.R. wrote:
> On 14/03/2019 03.29, Leslie Rhorer wrote:
> >> Not at all sure why you would want to do this, since this implies that
> >> the two are on the same partition.
> > 
> > What two are on the same partition?  /Backup and /Backup/Scrutiny?  Well, not necessarily, but in this case it is so. 
> 
> They have to be, or move is impossible (no pointer update possible
> across partitions). It will be then copy first, delete second.

Correct.  To be clear, in general /Dir1 and /Dir1/Dir2 do not have to be on the same partition.  They don't even have to be on the same host.  Any inode on a dev (it doesn't have to be a partition, and indeed neither of these arrays are partitioned at any level) can have its pointers updated to be a member of any directory on that same dev, but an inode on one dev cannot be assigned to a pointer on any other dev.  Pointers on any dev can only be assigned to inodes on the same dev.  Thus a move from one dev to another, regardless of type, can only be accomplished by physically copying all the data in the inodes to inodes on the other dev, creating new pointers on the second dev, and then deleting the pointers to the inodes on the first dev.

In this particular case, /Backup and /Backup/Scrutiny are on the same physical dev (specifically /dev/md0), so moving files by merely updating the directory structure is perfectly possible.  /RAID, on the other hand is not even on the same machine, so no directory update from /RAID to /Backup or vice versa is possible.  If I were moving files from /RAID to /Backup or from /Backup to /RAID, then some form of copy (in this case across a 10G TCP/IP link) followed by some form of delete.  I am not moving any files between /RAID and /Backup, however, so in this case the point is moot.

[toc] | [prev] | [next] | [standalone]


#54430

From"Carlos E.R." <robin_listas@es.invalid>
Date2019-03-14 18:22 +0100
Message-ID<e7fqlf-e1k.ln1@Telcontar.valinor>
In reply to#54407
On 13/03/2019 16.27, Leslie Rhorer wrote:
> I'm sorry, I should have mentioned these are giant files (up to 40GB), and lots of them.  A copy operation is definitely not practical.  It needs to be a file pointer update, such as a mv, not a copy-and-delete.

Somewhere, long ago, I used a command or a functionality in a file
browser called prune that did just that. But maybe it moved entire
directories.  However, I looked at "man prune" and I don't know what it
is talking about.

I also looked to see if "mc" has this functionality, but no.

-- 
Cheers, Carlos.

[toc] | [prev] | [next] | [standalone]


#54409

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 08:37 -0700
Message-ID<567eee08-44e0-4667-951e-e9ac36353f8d@googlegroups.com>
In reply to#54398
This is what I have, and it seems to work, but I'm just not very happy with it.

#! /bin/bash

cd /RAID/
while read File
do
        echo $File | grep -q /Backup/Scrutiny/
        [[ $? -eq 0 ]] && continue
        FName=${File##*/Backup/}
        [[ -a $FName ]]
        if [[ $? -ne 0 ]]
        then
                Dir=/Backup/Scrutiny/${FName%/*}/
                [[ -d "$Dir" ]] || mkdir -p "$Dir"
                mv "$File"  "$Dir"
        fi
done < <( find /Backup/ -type f )

[toc] | [prev] | [next] | [standalone]


#54419

FromWilliam Unruh <unruh@invalid.ca>
Date2019-03-13 21:10 +0000
Message-ID<q6brk9$skl$2@dont-email.me>
In reply to#54409
On 2019-03-13, Leslie Rhorer <lrhorer@mygrande.net> wrote:
> This is what I have, and it seems to work, but I'm just not very happy with it.

Why are you not happy? It is rather long and complicated (unnecessarily)
but so what.
 
>
> #! /bin/bash
>
> cd /RAID/
> while read File
> do
>         echo $File | grep -q /Backup/Scrutiny/
>         [[ $? -eq 0 ]] && continue
>         FName=${File##*/Backup/}
>         [[ -a $FName ]]
>         if [[ $? -ne 0 ]]
>         then
>                 Dir=/Backup/Scrutiny/${FName%/*}/
>                 [[ -d "$Dir" ]] || mkdir -p "$Dir"
>                 mv "$File"  "$Dir"
>         fi
> done < <( find /Backup/ -type f )
>

Are you sure that /RAID and /Backup/Scrutiny are on the same partition?
If not then this is a copy/erase process.

[toc] | [prev] | [next] | [standalone]


#54424

FromLeslie Rhorer <lrhorer@mygrande.net>
Date2019-03-13 19:07 -0700
Message-ID<24f18eff-53db-42c2-afef-d010d201e4f6@googlegroups.com>
In reply to#54419
On Wednesday, March 13, 2019 at 4:10:34 PM UTC-5, William Unruh wrote:
> On 2019-03-13, Leslie Rhorer wrote:
> > This is what I have, and it seems to work, but I'm just not very happy with it.
> 
> Why are you not happy? It is rather long and complicated (unnecessarily)
> but so what.

That is why I am not all that happy with it.  I prefer simple, elegant solutions, not complicated ones, and especially6 not unnecessarily complicated ones.


> >
> > #! /bin/bash
> >
> > cd /RAID/
> > while read File
> > do
> >         echo $File | grep -q /Backup/Scrutiny/
> >         [[ $? -eq 0 ]] && continue
> >         FName=${File##*/Backup/}
> >         [[ -a $FName ]]
> >         if [[ $? -ne 0 ]]
> >         then
> >                 Dir=/Backup/Scrutiny/${FName%/*}/
> >                 [[ -d "$Dir" ]] || mkdir -p "$Dir"
> >                 mv "$File"  "$Dir"
> >         fi
> > done < <( find /Backup/ -type f )
> >
> 
> Are you sure that /RAID and /Backup/Scrutiny are on the same partition?
> If not then this is a copy/erase process.

I am afraid you are incorrect.  You misread the code a bit.  I am not moving any file to or from /RAID.  All I am doing is looking to see if the files exist on /RAID.  If they do not, then they are moved from the main /Backup structure to the /Backup/Scrutiny structure to be examined and potentially deleted.  Otherwise they are left alone.  I have modified the code a bit and added some comments:

#! /bin/bash

cd /Backup
while read File
do
        FName=${File##*.}  # Remove the leading "."
        [[ -a /RAID$FName ]]   #check to see if the file exists on the /RAID share
        if [[ $? -ne 0 ]]   # If the file does not exist:
        then
                Dir=/Backup/Scrutiny/${FName%/*}   # Specify the new directory
                [[ -d "$Dir" ]] || mkdir -p "$Dir"   # Make sure it exists
                mv "$File"  "$Dir"   # Move the file to the new location
        fi
done < <( find ! -path "*Scrutiny*" ! -path "*System*"  -type f )  # Find all regular files on /Backup with the exception of those in /Backup/Scrutiny and /Backup/System

Note /Backup/System is a directory containing files pertinent to the local syste not found on /RAID, and if I don't exclude /Backup/Delete, then the script will infinitely recurse the Scrutiny directory and move the files to /Backup/Scrutiny/Scrutiny/Scrutiny...

Just FYI, /Backup is a RAID array on the local server, and /RAID is a RAID array on a remote system, mounted via NFS.  Every morning, an rsync session copies all new and updated files over from /RAID to /Backup.  This script allows me to manually look at any files deleted from /RAID to make sure I really want them deleted.

Note also the script ran in just under 1 minute, moving nearly 1TB of files.  Copy and delete would have taken nearly an hour.

[toc] | [prev] | [standalone]


Back to top | Article view | alt.os.linux


csiph-web