Results 1 to 9 of 9
Hi All,
Ok here's my little problem ...
Our SAMBA Server needs a clean up asap - so we decided to move all files that are older than january '09 ...
- 05-02-2011 #1
[SOLVED] mv files older than XY with directory structure
Hi All,
Ok here's my little problem ...
Our SAMBA Server needs a clean up asap - so we decided to move all files that are older than january '09 (accessdate or modify date) to an archive directory.
All networkshares and userfolders are located in the homedir - so I have created a file called date with access & modified date 01.01.2009 00:00:00 for checking whether a file is older or younger than that...
touch -t 0901010000 /home/date
find /home/ -not -newer /home/date -exec ls -lt {} \;
I recieved some output - checked some files whether the command is looking for access or modify date --> modify date!
If I just move a file that would be listed with my commands above, I lose the whole path, e.g:
/home/this/is/a/test/dir/file/older/than/2009/helloworld.txt
my archive would look like this:
./helloworld.dat, but I need the whole directorystructure too, needs to look like this:
./home/this/is/a/test/dir/file/older/than/2009/helloworld.txt
Is there an easy way to do that?
Thanks for your hints!
Greetings from Switzerland
- 05-02-2011 #2
Try something like this:
But please:
- do some dry runs before
- take care of circles (both source and destination seem to be in /home?)
- replace <DESTINATION_DIR> with an appropiate path
Code:find /home/ -not -newer /home/date -print0 | rsync --from0 -a --files-from=- / <DESTINATION_DIR>
You must always face the curtain with a bow.
- 05-02-2011 #3
Hi Irithori
Tried it but recieved a syntax error so I checked the mistake and changed the find command order.
find /home/testdir/ -print0 -not -newer /home/date | rsync --from0 -a --files-from=- / /path/to/nas/
with this commandline I get an almost 1:1 copy of the files from /home/testdir
- checked date stats, setup is correct
Why is it ignoring my date file?
Greetings and thanks a lot for your help
FabTK
- 05-02-2011 #4
The -newer switch should work.
Are you sure, the files havent been modified/copied in the meantime?
Because I understood from your first post, that you *did* get a good list of files already?You must always face the curtain with a bow.
- 05-03-2011 #5
Good Morning,
Yep I got already a "good" list but this list looks like this
[...]
/a/file/with/modified/flag/older/than/2009.xls
/another/file/with/modified/flag/older/than/2009.pdf
/yet/another/file.txt
[...]
If I would copy / mv these files, I would get a huge filecrowd in one folder - and that's the jumping point.
Will test it a few more times but in my first 2 or 3 runs I did get an almost 1:1 copy of the sourcefolder. Checked some dateflags of the files that have been moved - ofc the "old" files were there, but the "newer" files with access/modified/change > 2009 were there too ...
Greetings
FabTK
- 05-03-2011 #6
I just re-tested that oneliner and it works as expected.
Newer files/dirs than /home/date are *not* copied/created.
What I can think of:
a) if you are sure, that the filelist provided by find is ok, then you might have a rsync with a slightly different behaviour.
Maybe try to find only files? find -type f
b) the filelist is not ok, and just matches almost all files. Wrong mtime on the source files?You must always face the curtain with a bow.
- 05-03-2011 #7
You were to fast, just wanted to edit my reply

I'm just too stupid, I set the print0 parameter before the newer statement...
Just find old files (needed to exclude dirs and hidden dirs/files)
find /home/ \( ! -regex '.*/\..*' \) -type f -not -newer /home/date -print0
combination of your input and my decent knowledge
find /home/ \( ! -regex '.*/\..*' \) -type f -not -newer /home/date -print0 | rsync --from0 -a --files-from=- / /path/to/nas
works great ofc!
Atm, the script is just copying "old" files into a new directory - if there would be a possibilty to move I would be very happy (or I just delete all the "old" files after successfull copy-job)
Thanks a lot for your help
Greetings FabTK
- 05-03-2011 #8
Good to hear.
If you are really, really, *really* sure, that all old files have been copied,
then you could run the same find again, with -type f -delete (and without -print0)
Btw, your backup does work, right?
You must always face the curtain with a bow.
- 05-03-2011 #9
yep, our backup is working correctly^^
after re-reading some manpages - this command looks pretty simple and logic now... NOW ...
thanks a lot for your help, really appreciate it!
Greetings FabTK



