How to handle files in use during Tar?

How you do usually deal with files in use during a backup?
Is there a option to let TAR skip opened files?
Or notify me an opened file is tar'ed?

What's the best practice?

Thanks

1 Like

AFAIK, there is no such option.

But there should be some best method to achieve this, am also waiting along with you for some experts to answer us this. Good question anyway.

AFAIK, tar doesn't care about open files anyway. It just cares about the data associated with a file. And in order to get a clean state (no process writing a file while it's being read) we usually split the VG mirror, mount it on a different machine, and run the backup from there. Once it's done we re-sync the mirror with the active part.

I'm sure there are people who can improve on this.

#!/bin/ksh                      
list=`ls x*`                    
i=0                             
for file in $list               
do                              
        echo $file              
        fuser $file             
        if [ $? = 0 ]           
        then                    
         if [ i -eq 0 ]         
         then                   
          tar cvnf y2.tar $file 
          i=1                   
         else                   
          tar uvnf y2.tar $file 
         fi                     
        else                    
          echo $file in use     
        fi                      
done                   

I think that the u option on the second tar statement can by replaced with r.