Page 1 of 1

20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 15:00
by fulltilt
Ich muss ein Backup eines Ordners wiederherstellen - mit cp komme ich nicht weiter ... Argumentliste zu lang ...

Code: Select all

cp -f ./Backups/var/www/virtual/auktion/htdocs/uplimg/* ./var/www/virtual/auktion/htdocs/uplimg/
Habe dann versucht:

Code: Select all

cd /Backups/var/www/virtual/auktion/htdocs/uplimg

Code: Select all

cp -f * /var/www/virtual/auktion/htdocs/uplimg
Klappt auch nicht - es handelt sich um ca 20000 Dateien .jpg & .img

Wie kann ich diese vielen Dateien kopieren?

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 15:42
by Joe User
Quick&Dirty&Untested:

Code: Select all

cd /old/data/dir && tar cpf - . | tar xpf - -C /new/data/dir

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 18:00
by aubergine
oder ohne zu packen/entpacken mit:

Code: Select all

find /Backups/var/www/virtual/auktion/htdocs/uplimg/ -type f -exec mv {} /var/www/virtual/auktion/htdocs/uplimg/ ;

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 18:06
by fulltilt
Danke - hat geklappt :-)
aubergine wrote:oder ohne zu packen/entpacken mit:

Code: Select all

find /Backups/var/www/virtual/auktion/htdocs/uplimg/ -type f -exec mv {} /var/www/virtual/auktion/htdocs/uplimg/ ;

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 18:32
by oxygen
fulltilt wrote:Ich muss ein Backup eines Ordners wiederherstellen - mit cp komme ich nicht weiter ... Argumentliste zu lang ...

Code: Select all

cp -fR ./Backups/var/www/virtual/auktion/htdocs/uplimg/* ./var/www/virtual/auktion/htdocs/uplimg/
Habe dann versucht:

Code: Select all

cd /Backups/var/www/virtual/auktion/htdocs/uplimg

Code: Select all

cp -f * /var/www/virtual/auktion/htdocs/uplimg
Klappt auch nicht - es handelt sich um ca 20000 Dateien .jpg & .img

Wie kann ich diese vielen Dateien kopieren?
Das Problem ist in dem Fall das *. Die bash baut daraus die Argumentliste. Wenn möglich solltest du einfach
cp -fR ./Backups/var/www/virtual/auktion/htdocs/uplimg ./var/www/virtual/auktion/htdocs/
verwenden. Weitere bzw. bessere Möglichkeit als find (mit -exec sau lahm) und tar (hässlich):
cd Backups/var/www/virtual/auktion/htdocs/uplimg
ls . | xargs -i cp "{}" /var/www/virtual/auktion/htdocs/uplimg
Bzgl. find kann ich nur wiederhohlen das man -exec möglichst vermeiden sollte. lieber mit xargs arbeiten.

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 19:15
by hornox
man xargs wrote: -I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate
input items; instead the separator is the newline character. Implies -x and -L 1.

--replace[=replace-str], -i[replace-str]
This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise. This option is deprecated; use -I instead.

-L max-lines
Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next
input line. Implies -x.
Heißt das nicht das auch mit der obigen xargs Version für jede Datei ein cp gestartet wird und xargs in dem Fall genauso langsam wie find -exec ist?

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Posted: 2007-04-21 23:16
by daemotron
Alternativ kannst Du auch an den Kernel-Sourcen rumfummeln, um für Argumentlisten mehr Speicher zur Verfügung zu stellen. Wie das genau zu bewerkstelligen ist, kannst Du hier lesen: http://www.rootforum.org/forum/viewtopi ... 289#283632