On 9/6/13, Craig L. <cr...@gtek.biz> wrote:
> On Wed, Sep 04, 2013 at 07:16:42AM +1000, Zenaan Harkness wrote:

>> > Both seem to be trying to copy the string '{}' and the directory
>> > /var/data.backup/ to the directory name that is being piped to
>> > xargs, the name of the found file in this case, which is how I
>> > understand xargs to funtion. Regardless, I get the same error to
>> > both:
>> >
>> >    "cp: target `dump_08-31-13.sql' is not a directory"
>>
>> Ah yes, well then an argument to cp should do it:
>> ... | xargs cp -t /var/data.backup/
>>
>> ought to do the job. And you can test first with the following:
>> ... | xargs echo cp -t /var/data.backup/
>>             ^^^^
>
> This works in that it copies the found files to /var/data.backup, but does
> not
> rename it in the process. I'm on another system right now without
> PostgreSQL,
> but my testing was as follows:
>    mkdir /tmp/var
>    mkdir /tmp/data.backup
>    touch /tmp/var/test.sql
>    find /tmp/var -mmin -60 -a -iname '*.sql' 2>/dev/null | \
>       xargs echo cp -t /tmp/data.backup
>
> which outputs this:
>    cp -t /tmp/data.backup /tmp/var/test.sql

Sorry, I forgot you needed renaming. So -I option to xargs may be
useful for you.

OK, try something like this:

  sh -c 'cp "$0" /tmp/data.backup/${HOSTNAME}".${0:2}"' {} \;

find /tmp/var -mmin -60 -a -iname '*.sql' -type f \
 | xargs -n 50 basename -a \
 | xargs -I NAME echo cp /tmp/data.backup/NAME \
 /tmp/var/$HOSTNAME.`date +%Y%m%d-%H.%M.%S.%N`.NAME.backup

You should be bonza, fab, good to go :)

Let us know if that does the trick,
Zenaan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/caosgnsrevtp3wew58jj31mremt60xk+3iqipdnwdjg7_ifj...@mail.gmail.com

Reply via email to