home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 August - Disc 1 / PCNET_CD_2006_08_1.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / snapmerge < prev    next >
Encoding:
Text File  |  2006-04-17  |  1.3 KB  |  71 lines

  1. #!/bin/sh
  2. #vim:filetype=sh
  3.  
  4. if [ "$#" -lt "2" ]
  5. then
  6. cat 1>&2 <<HERE
  7. $0 merges Unionfs snapshots onto the base.
  8. $0 base snap0 [ snap1 ... ]
  9.  
  10. If you want to merge two or more consecutive snapshots to create a new
  11. snapshot, as if snap1, snap0 are two branches that are mounted over base, you
  12. can not directly call snapmerge because whiteouts are not handled.  Instead,
  13. you should create a new Unionfs that merges an empty directory snap10 and base
  14. (with base=ro).  Then you can run snapmerge /mnt/unionfs snap0 snap1.  snap10
  15. will contain the merged snapshot, with only the proper number of whiteouts.
  16. HERE
  17.     exit 1
  18. fi
  19.  
  20. BASE=$1
  21.  
  22. shift
  23.  
  24. WD=`pwd`
  25. if [ ! `echo $BASE | cut -b1` = "/" ] ; then
  26.     BASE="$WD/$BASE"
  27. fi
  28.  
  29. while [ ! -z "$1" ]
  30. do
  31.     SNAP=$1
  32.     if [ ! -d $SNAP ] ; then
  33.         echo "$0: $SNAP not a directory" 1>&2
  34.         exit 1
  35.     fi
  36.  
  37.     cd $SNAP || exit 1
  38.  
  39.     echo "Merging $SNAP onto $BASE."
  40.  
  41.     # Directories
  42.     find . -type d | tail +2 |  sed -e 's/\.\///' |
  43.     while read N
  44.     do
  45.         mkdir -p $BASE/$N
  46.         chmod $BASE/$N --reference=$N
  47.         touch $BASE/$N --reference=$N
  48.     done
  49.  
  50.     # Copy Files
  51.     find . -not \( -regex '.*/\.wh\.[^/]*' -type f \) -not -type d |  sed -e 's/\.\///' |
  52.     while read N
  53.     do
  54.         cp -a $N $BASE/$N
  55.     done
  56.  
  57.     # Handle Whiteouts
  58.     find . \( -regex '.*/\.wh\.[^/]*' -type f \) | sed -e 's/\.\///;s/\.wh\.//' |
  59.     while read N
  60.     do
  61.         rm -rf $BASE/$N
  62.     done
  63.  
  64.     cd $WD
  65.     shift
  66. done
  67.  
  68. cd $WD
  69.  
  70. exit 0
  71.