bash - Strange results using Linux find -


i trying set backup shell script shall run once per week on server , keep weekly backups ten weeks , works well, except 1 thing...

i have folder contains many rather large files, ten weekly backups of folder take quite large amount of disk space , many of larger files in folder change, thought split backup of folder in two: 1 smaller files included in 'normal' weekly backup (and kept ten weeks) , 1 file larger files updated every week, without older weekly versions being kept.

i have used following command larger files:

/usr/bin/find /other/projects -size +100m -print0 | /usr/bin/xargs -0 /bin/tar -rvpf /backup/prj-files_large.tar 

that works expected. tar -v option there debugging. however, when archiving smaller files, use similar command:

/usr/bin/find /other/projects -size -100m -print0 | /usr/bin/xargs -0 /bin/tar -rvpf /backup/prj-files_$file_end.tar 

where $file_end weekly number. line above not work. had script run other day , took hours , produced file 70 gb, though expected output size 14 gb (there lot of files). seems there duplication of files in large file, have not been able check though. yesterday ran command above smaller files command line , see files know larger 100 mb included.

however, ran find /other/projects -size -100m command line , produced expected list of files.

so, if has ideas doing wrong appreciate tips or pointers. file names include spaces , sorts of characters, e.g. single quote, if has it.

the thing can think of not using xargs , admittedly not familiar that, still think problem lies in use of find since find gives input xargs.

first of all, not know if considered bad form or not answer own question, doing anyway since realised error , wanted close , able having same problem had.

now, once realised did wrong frankly bit embarrassed did not see earlier, it:

i did experimental runs command line , after while realised output not listed files, listed directories themselves. directories of course files , smaller 100m have (most anyway) been included , when have been included, files in them have been included, regardless of sizes. explain why output file 5 times larger expected.

so, in order overcome added -type f, includes regular files, find command , lo , behold, worked!

to recap, adjusted command use smaller files now:

/usr/bin/find /other/projects -size -100m -type f -print0 | /usr/bin/xargs -0 /bin/tar -rvpf /backup/prj-files_$file_end.tar 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -