20000 Dateien nach Ordner X kopieren - bricht ab

Backup, Restore und Transfer von Daten
fulltilt
Posts: 366
Joined: 2006-08-27 02:06
 

20000 Dateien nach Ordner X kopieren - bricht ab

Post 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?
User avatar
Joe User
Project Manager
Project Manager
Posts: 11183
Joined: 2003-02-27 01:00
Location: Hamburg
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post by Joe User »

Quick&Dirty&Untested:

Code: Select all

cd /old/data/dir && tar cpf - . | tar xpf - -C /new/data/dir
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
aubergine
Posts: 471
Joined: 2005-09-10 17:52
Location: Frankfurt am Main
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post 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/ ;
fulltilt
Posts: 366
Joined: 2006-08-27 02:06
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post 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/ ;
oxygen
Posts: 2138
Joined: 2002-12-15 00:10
Location: Bergheim
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post 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.
hornox
Posts: 139
Joined: 2005-09-22 23:09
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post 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?
User avatar
daemotron
Administrator
Administrator
Posts: 2641
Joined: 2004-01-21 17:44
 

Re: 20000 Dateien nach Ordner X kopieren - bricht ab

Post 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