|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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-- |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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/ |
|
![]() |
| Outils de la discussion | |
|
|