PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > find -exec command
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

find -exec command

Réponse
 
LinkBack Outils de la discussion
Vieux 02/11/2006, 17h30   #1
mark.pollard@cwfi.co.fk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut find -exec command

I am currently struggling with a command that will look for files newer
than a specified file and tar them to a new file in a bash shell. The
command I am trying to use is

find test -newer last_backup -exec tar rvf backup.tar '{}' \;

Where test = folder containg files
last_backup = specified file
backup.tar = new file

It will work in Solaris, unfortunately the system i need to back up is
LINUX. I can get the 'find -newer last_backup' to work fine however the
-exec bit doesnt work, every file is tar'd instead of just the newer
ones.

Any would be greatly appreciated.

  Réponse avec citation
Vieux 02/11/2006, 17h38   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

2006-11-2, 09:30(-08), mark.pollard@cwfi.co.fk:
> I am currently struggling with a command that will look for files newer
> than a specified file and tar them to a new file in a bash shell. The
> command I am trying to use is
>
> find test -newer last_backup -exec tar rvf backup.tar '{}' \;
>
> Where test = folder containg files
> last_backup = specified file
> backup.tar = new file
>
> It will work in Solaris, unfortunately the system i need to back up is
> LINUX. I can get the 'find -newer last_backup' to work fine however the
> -exec bit doesnt work, every file is tar'd instead of just the newer
> ones.

[...]

If using GNU tar, add the --no-recursion option to tar.

Alternatively, you may want to add "! -type d" to find.

--
Stéphane
  Réponse avec citation
Vieux 02/11/2006, 18h44   #3
Todd H.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

Stephane CHAZELAS <this.address@is.invalid> writes:

> 2006-11-2, 09:30(-08), mark.pollard@cwfi.co.fk:
> > I am currently struggling with a command that will look for files newer
> > than a specified file and tar them to a new file in a bash shell. The
> > command I am trying to use is
> >
> > find test -newer last_backup -exec tar rvf backup.tar '{}' \;
> >
> > Where test = folder containg files
> > last_backup = specified file
> > backup.tar = new file
> >
> > It will work in Solaris, unfortunately the system i need to back up is
> > LINUX. I can get the 'find -newer last_backup' to work fine however the
> > -exec bit doesnt work, every file is tar'd instead of just the newer
> > ones.

> [...]
>
> If using GNU tar, add the --no-recursion option to tar.
>
> Alternatively, you may want to add "! -type d" to find.


I've never used single ticks around the {} with a find -exec. Try it
without those and see if it becomes happy.

--
Todd H.
http://www.toddh.net/
  Réponse avec citation
Vieux 02/11/2006, 18h55   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

2006-11-02, 12:44(-06), Todd H.:
[...]
>> > find test -newer last_backup -exec tar rvf backup.tar '{}' \;
>> >
>> > Where test = folder containg files
>> > last_backup = specified file
>> > backup.tar = new file
>> >
>> > It will work in Solaris, unfortunately the system i need to back up is
>> > LINUX. I can get the 'find -newer last_backup' to work fine however the
>> > -exec bit doesnt work, every file is tar'd instead of just the newer
>> > ones.

>> [...]
>>
>> If using GNU tar, add the --no-recursion option to tar.
>>
>> Alternatively, you may want to add "! -type d" to find.

>
> I've never used single ticks around the {} with a find -exec. Try it
> without those and see if it becomes happy.


That would make no difference. The single ticks are for the
shell to tell it to take the {} characters litterally (which
most shells do anyway already even without the '...').

In both cases, find will be given an argument containing the two
characters "{}".

The problem the OP is having is that find will select the
*directories* that are newer than the "last_backup" file. And
GNU tar, when given a directory, will archive the directory plus
every file it contains by default. Hence the --no-recursion to
revert that default behavior.

--
Stéphane
  Réponse avec citation
Vieux 03/11/2006, 02h27   #5
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

In article <slrnekkfo5.fc9.stephane.chazelas@spam.is.invalid> ,
Stephane CHAZELAS <this.address@is.invalid> wrote:

> 2006-11-02, 12:44(-06), Todd H.:
> [...]
> >> > find test -newer last_backup -exec tar rvf backup.tar '{}' \;
> >> >
> >> > Where test = folder containg files
> >> > last_backup = specified file
> >> > backup.tar = new file
> >> >
> >> > It will work in Solaris, unfortunately the system i need to back up is
> >> > LINUX. I can get the 'find -newer last_backup' to work fine however the
> >> > -exec bit doesnt work, every file is tar'd instead of just the newer
> >> > ones.
> >> [...]
> >>
> >> If using GNU tar, add the --no-recursion option to tar.
> >>
> >> Alternatively, you may want to add "! -type d" to find.

> >
> > I've never used single ticks around the {} with a find -exec. Try it
> > without those and see if it becomes happy.

>
> That would make no difference. The single ticks are for the
> shell to tell it to take the {} characters litterally (which
> most shells do anyway already even without the '...').
>
> In both cases, find will be given an argument containing the two
> characters "{}".
>
> The problem the OP is having is that find will select the
> *directories* that are newer than the "last_backup" file. And
> GNU tar, when given a directory, will archive the directory plus
> every file it contains by default. Hence the --no-recursion to
> revert that default behavior.


That behavior is hardly specific to GNU tar. In fact, it's probably the
most common way that tar is used on most systems.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 03/11/2006, 10h55   #6
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

mark.pollard@cwfi.co.fk writes:

> I am currently struggling with a command that will look for files newer
> than a specified file and tar them to a new file in a bash shell. The
> command I am trying to use is
>
> find test -newer last_backup -exec tar rvf backup.tar '{}' \;


You're taring directories as well, try:

find test -type f -newer last_backup -exec tar rvf backup.tar {} \;

BTW. If you don't care much about portability and have GNU tools, you
may try faster method:

find test -type f -newer last_backup -print0 | \
xargs -0 --no-run-if-empty tar rvf backup.tar

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 03/11/2006, 11h04   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

2006-11-03, 11:55(+01), Michal Nazarewicz:
> mark.pollard@cwfi.co.fk writes:
>
>> I am currently struggling with a command that will look for files newer
>> than a specified file and tar them to a new file in a bash shell. The
>> command I am trying to use is
>>
>> find test -newer last_backup -exec tar rvf backup.tar '{}' \;

>
> You're taring directories as well, try:
>
> find test -type f -newer last_backup -exec tar rvf backup.tar {} \;
>
> BTW. If you don't care much about portability and have GNU tools, you
> may try faster method:
>
> find test -type f -newer last_backup -print0 | \
> xargs -0 --no-run-if-empty tar rvf backup.tar


Why use non-standard features when the standard find has a
better equivalent:

find test ! -type d -newer last_backup -exec \
tar rvf backup.tar {} +

(note that -type f is not the same as ! type d).

--
Stéphane
  Réponse avec citation
Vieux 04/11/2006, 08h09   #8
Kaz Kylheku
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec command

mark.pollard@cwfi.co.fk wrote:
> I am currently struggling with a command that will look for files newer
> than a specified file and tar them to a new file in a bash shell.


Since you're using GNU bash, why not use GNU tar as well.

> The command I am trying to use is
>
> find test -newer last_backup -exec tar rvf backup.tar '{}' \;


GNU tar has some incremental backup features. Look into the -g option
(whose long name is --listed-incremental):

Here is a simple demonstration:

tar -czvf foo-backup.tar.gz -g foo-backup.snap foo

This will tar and gzip up the directory foo/, and also create a
snapshot file "foo-backup.snap".

Now repeat the same command. This time, nothing happens. GNU tar looks
at the snapshot and the directory, and determines that nothing has
changed, and so the archive doesn't have to be updated.

Now create a new file under foo/, or touch an existing one, and re-run
the command. The new files are picked up.

By managing copies of the snapshot file and the archive, you can
implement a backup scheme with multiple dump levels. With such a
scheme, you can, for instance, have the ability to retrieve the version
of a file as it existed yesterday, last week, or last month. To do
that, you'd do a level zero (i.e. full backup) every month, weekly
level 1 dumps, and daily level 2 dumps.

Read the GNU info manual for tar:
http://www.gnu.org/software/tar/manual/

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15728 seconds with 16 queries