Script to Copy Files Conditionally

  • Follow


Hi

i need a short script to copy files from one drive to an archive drive. 
Have been using cmds like cp -pfR from one drive to another, but it 
would be more efficient if the copy were conditional on the date / time 
difference between source / destination file.

Have been looknig for a way to do this, but am no script expert and any 
pointers to relevant commands or examples would be appreciated...

Chris



----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/4/2007 4:21:08 PM

On Wed, 04 Apr 2007 16:21:08 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> i need a short script to copy files from one drive to an archive
> drive. Have been using cmds like cp -pfR from one drive to another,
> but it would be more efficient if the copy were conditional on the
> date / time difference between source / destination file.
>
> Have been looknig for a way to do this, but am no script expert and
> any pointers to relevant commands or examples would be appreciated...

rsync
0
Reply Frank 4/4/2007 4:43:15 PM


Frank Cusack wrote:
> On Wed, 04 Apr 2007 16:21:08 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> 
>>i need a short script to copy files from one drive to an archive
>>drive. Have been using cmds like cp -pfR from one drive to another,
>>but it would be more efficient if the copy were conditional on the
>>date / time difference between source / destination file.
>>
>>Have been looknig for a way to do this, but am no script expert and
>>any pointers to relevant commands or examples would be appreciated...
> 
> 
> rsync

Thanks. Just looked at that and will probably build and have a look, but 
really only need to mirror files on the same machine. A cron driven 
script would be more appropriate in this case...

Chris


-- 

----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/4/2007 5:15:39 PM

On Wed, 04 Apr 2007 17:15:39 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> Frank Cusack wrote:
>> On Wed, 04 Apr 2007 16:21:08 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
>>
>>>i need a short script to copy files from one drive to an archive
>>>drive. Have been using cmds like cp -pfR from one drive to another,
>>>but it would be more efficient if the copy were conditional on the
>>>date / time difference between source / destination file.
>>>
>>>Have been looknig for a way to do this, but am no script expert and
>>>any pointers to relevant commands or examples would be appreciated...
>>
>>
>> rsync
>
> Thanks. Just looked at that and will probably build and have a look,
> but really only need to mirror files on the same machine. A cron
> driven script would be more appropriate in this case...

0 0 * * * rsync src dst

-frank
0
Reply Frank 4/4/2007 5:32:56 PM

Frank Cusack wrote:
> On Wed, 04 Apr 2007 17:15:39 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> 
>>Frank Cusack wrote:
>>
>>>On Wed, 04 Apr 2007 16:21:08 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
>>>
>>>
>>>>i need a short script to copy files from one drive to an archive
>>>>drive. Have been using cmds like cp -pfR from one drive to another,
>>>>but it would be more efficient if the copy were conditional on the
>>>>date / time difference between source / destination file.
>>>>
>>>>Have been looknig for a way to do this, but am no script expert and
>>>>any pointers to relevant commands or examples would be appreciated...
>>>
>>>
>>>rsync
>>
>>Thanks. Just looked at that and will probably build and have a look,
>>but really only need to mirror files on the same machine. A cron
>>driven script would be more appropriate in this case...
> 
> 
> 0 0 * * * rsync src dst
> 
> -frank

Thanks, but it's still overkill, when a one or two line script would 
probably get the job done just as well :-).

What happened to all the arcane skills of unix, a single tool to do a 
single job well, specialisation over generalisation etc, or has it all 
morphed into the bloatware that is modern Linux ?...

Chris

-- 

----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/4/2007 6:14:56 PM

On Wed, 04 Apr 2007 18:14:56 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> Frank Cusack wrote:
>> On Wed, 04 Apr 2007 17:15:39 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
>>
>>>Frank Cusack wrote:
>>>
>>>>On Wed, 04 Apr 2007 16:21:08 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
>>>>
>>>>
>>>>>i need a short script to copy files from one drive to an archive
>>>>>drive. Have been using cmds like cp -pfR from one drive to another,
>>>>>but it would be more efficient if the copy were conditional on the
>>>>>date / time difference between source / destination file.
>>>>>
>>>>>Have been looknig for a way to do this, but am no script expert and
>>>>>any pointers to relevant commands or examples would be appreciated...
>>>>
>>>>
>>>>rsync
>>>
>>>Thanks. Just looked at that and will probably build and have a look,
>>>but really only need to mirror files on the same machine. A cron
>>>driven script would be more appropriate in this case...
>>
>>
>> 0 0 * * * rsync src dst
>>
>> -frank
>
> Thanks, but it's still overkill, when a one or two line script would
> probably get the job done just as well :-).

You may have lost me here.

How is a 1 or 2 line script LESS work or LESS overkill than a single
line cron entry.  Here's your one line script:

--8<---
#!/bin/sh
rsync $1 $2
--8<---

Or does the smiley indicate you are joking?

> What happened to all the arcane skills of unix, a single tool to do a
> single job well, specialisation over generalisation etc, or has it all
> morphed into the bloatware that is modern Linux ?...

You've really lost me there.  rsync is a single tool that does its
single highly specialized job quite well.

-frank
0
Reply Frank 4/4/2007 6:33:44 PM

Frank Cusack wrote:

> 
> You've really lost me there.  rsync is a single tool that does its
> single highly specialized job quite well.
> 
> -frank

Not a windup, just the gut feeling that Solaris probably already has 
scriptable commands that would do such a simple job. Just looking for a 
solution that doesn't involve installing yet more software with 
attendant demons etc.

If there isn't such a solution, then rsync does look like the way forward...

Chris



----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/4/2007 9:41:41 PM

On Wed, 04 Apr 2007 21:41:41 GMT ChrisQuayle <nospam@devnul.co.uk> wrote:
> Frank Cusack wrote:
>
>>
>> You've really lost me there.  rsync is a single tool that does its
>> single highly specialized job quite well.
>>
>> -frank
>
> Not a windup, just the gut feeling that Solaris probably already has
> scriptable commands that would do such a simple job.

It does.  I was just giving you the easiest possible method.

> Just looking for a solution that doesn't involve installing yet more
> software with attendant demons etc.

rsync doesn't need any daemon, etc., but I agree installing ever more
and more software is a PITA for smaller shops.  rsync is a standard
tool, Solaris is deficient for not having it by default.

> If there isn't such a solution, then rsync does look like the way forward...

rsync is much easier, and much more efficient than any other method.

One example of how to do it with the built-in tools:

(cd src && find . -depth) | cpio -pdm dst

but then you have to do some moderate post-processing (on the output from
cpio) to exclude error messages about not copying files that are already
newer (while still reporting other errors).

If you have GNU tar (same problem with rsync though, you need addt'l
software), you can use the --newer option to get pretty close to what
rsync would do.

-frank
0
Reply Frank 4/4/2007 10:22:33 PM

On 2007-04-04 22:41:41 +0100, ChrisQuayle <nospam@devnul.co.uk> said:

> Not a windup, just the gut feeling that Solaris probably already has 
> scriptable commands that would do such a simple job. Just looking for a 
> solution that doesn't involve installing yet more software with 
> attendant demons etc.

rsync ships as a package on the Solaris 10 software companion.  I'm not 
sure about earlier releases, but if it's not on the companion CDs there 
are undoubtedly packages at sunfreeware.  There's no daemon (you can 
run rsync as a daemon but you don't need to and no daemon is set up by 
default).

> 
> If there isn't such a solution, then rsync does look like the way forward...

It's a fantastically useful tool for mirroring things.

0
Reply Tim 4/5/2007 7:02:26 AM

On 2007-04-05, Tim Bradshaw <tfb@tfeb.org> wrote:
> On 2007-04-04 22:41:41 +0100, ChrisQuayle <nospam@devnul.co.uk> said:
>
>> Not a windup, just the gut feeling that Solaris probably already has 
>> scriptable commands that would do such a simple job. Just looking for a 
>> solution that doesn't involve installing yet more software with 
>> attendant demons etc.

man find

Look at the time related, -exec & -cpio options.

>
> rsync ships as a package on the Solaris 10 software companion.  I'm not 
> sure about earlier releases, but if it's not on the companion CDs there 
> are undoubtedly packages at sunfreeware. 

pkg-get install rsync

Not hard ...


-- 
Ignorance more frequently begets confidence than does knowledge: it is those
who know little, not those who know much, who so positively assert that this
            or that problem will never be solved by science.
            [email me at huge {at} huge (dot) org <dot> uk]
0
Reply Huge 4/5/2007 9:49:38 AM

On Apr 5, 10:49 am, Huge <H...@nowhere.much.invalid> wrote:
> On 2007-04-05, Tim Bradshaw <t...@tfeb.org> wrote:

> pkg-get install rsync
>
> Not hard ...

I live in absolute terror of pkg-get (at least the blastwave one). 3
times out of 10 it will do what you want, 6 times out of 10 it will
install a new version of gnome and/or libc which it will take a day to
excise from the machin, once out of 10 you will need an exorcist,
bleach and a flamethrower.

--tim

(yes, I know, it's not really that bad and what it's trying to do
makes sense in context.)

0
Reply Tim 4/5/2007 10:46:37 AM

On 2007-04-05, Tim Bradshaw <tfb+google@tfeb.org> wrote:
> On Apr 5, 10:49 am, Huge <H...@nowhere.much.invalid> wrote:
>> On 2007-04-05, Tim Bradshaw <t...@tfeb.org> wrote:
>
>> pkg-get install rsync
>>
>> Not hard ...
>
> I live in absolute terror of pkg-get (at least the blastwave one). 3
> times out of 10 it will do what you want, 6 times out of 10 it will
> install a new version of gnome and/or libc which it will take a day to
> excise from the machin, once out of 10 you will need an exorcist,
> bleach and a flamethrower.

It does have a habit of installing 200Gb of stuff when all you wanted
was a new version of "less", I admit, but it's never broken anything
here, and since it uses its own libraries and directory trees, it's
easy enough to remove.

-- 
Ignorance more frequently begets confidence than does knowledge: it is those
who know little, not those who know much, who so positively assert that this
            or that problem will never be solved by science.
            [email me at huge {at} huge (dot) org <dot> uk]
0
Reply Huge 4/5/2007 11:06:42 AM

Huge wrote:
> On 2007-04-05, Tim Bradshaw <tfb+google@tfeb.org> wrote:
> 
>>On Apr 5, 10:49 am, Huge <H...@nowhere.much.invalid> wrote:
>>
>>>On 2007-04-05, Tim Bradshaw <t...@tfeb.org> wrote:
>>
>>>pkg-get install rsync
>>>
>>>Not hard ...
>>
>>I live in absolute terror of pkg-get (at least the blastwave one). 3
>>times out of 10 it will do what you want, 6 times out of 10 it will
>>install a new version of gnome and/or libc which it will take a day to
>>excise from the machin, once out of 10 you will need an exorcist,
>>bleach and a flamethrower.
> 
> 
> It does have a habit of installing 200Gb of stuff when all you wanted
> was a new version of "less", I admit, but it's never broken anything
> here, and since it uses its own libraries and directory trees, it's
> easy enough to remove.
> 

Took your advice and built rsync. Couldn't find a binary for sol8, so 
downloaded the source and it built (only one warning !) and was running 
in about 15 minutes. It appears to copy the whole tree on the first run 
through identical src/dst trees, but nothing on a second run. Still 
thinking about the script though - puzzle. find $1 -newer $2 > files 
will pull out the differences, but still work to do building the args to 
cp.

The systems here need very little sysadmin, so never really spend enough 
time to get up to speed on scripting. Have Kernighan and Pike, sed & awk 
  and the man pages and that's about it, so a good book on scripting 
wouldn't be a bad idea...

Chris


-- 

----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/5/2007 10:15:23 PM

On 2007-04-05 23:15:23 +0100, ChrisQuayle <nospam@devnul.co.uk> said:

> Took your advice and built rsync. Couldn't find a binary for sol8, so 
> downloaded the source and it built (only one warning !) and was running 
> in about 15 minutes.

http://www.sunfreeware.com/programlistsparc8.html#rsync

> It appears to copy the whole tree on the first run through identical 
> src/dst trees, but nothing on a second run.

That's what it should do.

0
Reply Tim 4/6/2007 7:08:18 AM

Tim Bradshaw wrote:
> On 2007-04-05 23:15:23 +0100, ChrisQuayle <nospam@devnul.co.uk> said:
> 
>> Took your advice and built rsync. Couldn't find a binary for sol8, so 
>> downloaded the source and it built (only one warning !) and was 
>> running in about 15 minutes.
> 
> 
> http://www.sunfreeware.com/programlistsparc8.html#rsync
> 
>> It appears to copy the whole tree on the first run through identical 
>> src/dst trees, but nothing on a second run.
> 
> 
> That's what it should do.
> 

There was a binary listed, but there were dependencies which looked like 
a hassle. Often download, then use pkgadd, but It takes so little time 
to do a build from source. It's easier to see what's going on and what 
gets put where from a Makefile. As for copy the whole tree, that's fine 
- some files didn't get copied. Msg was: chown failed, invalid arg 22, 
probably ro files, but will find out.

Approx 13 gbytes rsync ran overnight at 648 K bytes per second from 
local drive to local A5100 on Disksuite. The speed hit is probably due 
to software raid, which seems to peak at around 1.5 Mbytes second flat out.

Overall, good stuff & many thanks...

Chris


-- 

----------------------
Greenfield Designs Ltd
Electronic and Embedded System Design
Oxford, England
(44) 1865 750 681
0
Reply ChrisQuayle 4/6/2007 9:20:16 AM

14 Replies
159 Views

(page loaded in 0.12 seconds)

Similiar Articles:


















7/14/2012 3:46:15 AM


Reply: