File: bootcdbackup.lib

package info (click to toggle)
bootcd 3.10%2Bnmu1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 508 kB
  • ctags: 128
  • sloc: sh: 3,935; makefile: 117
file content (133 lines) | stat: -rw-r--r-- 3,855 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# bootcdbackup.lib
# vim: set filetype=sh :

run_cpiostar_kern()
{
  local use_type=$1 # star|cpio
  echo >&2 "backup to $backupdir with $use_type"

  # exclude all files and directories 
  (cd $dir; find . -print0 | 
    sed -e "s|^|\x00|;$ext;s|^\x00||" | 
    (
    if [ "$use_type" = "star" ]; then
      sed "s|\x00|\n|g" | star -xattr -H=exustar -c list=- -f -
    else
      cpio --null --quiet -o
    fi
    ) |
    gzip -c |
    split -b2000m -d - $backupdir/$use_type)
}

# bootcdbackup.lib
# vim: set filetype=sh :

# function: run_cpiostar -- backup the partition and split into files < 2GB 
#                      (mkisofs restriction!)
# get: $n -- -d <dir> the "root" directory (optional)
#      $n -- -u <cpio|star> 
#      $last -- backupdir (write backup to this directory)
# need: RCPIO_EXCLUDE_DIRS -- exclude this files / directories
run_cpiostar()
{
  local ext=""
  local use_type="auto" # cpio or star
  local dir=/
  local selinux=""
  local star=""
  local interact=""

  while [ $# -gt 1 ]; do
    if [ "$1" = "-d" ]; then
      dir=$2
      shift 2
    elif [ "$1" = "-u" ]; then
      use_type=$2
      shift 2
    elif [ "$1" = "-i" ]; then
      interact="$1"
      shift
    else
      err "run_cpiostar: unknown argument: <$1>"
    fi
  done

  local backupdir="$1"
  shift
  [ "$backupdir" ] || err "run_cpiostar argument missing"

  if [ -f $dir/etc/selinux/config ]; then
    if [ "$(cat "$dir/etc/selinux/config" | \
      grep -e "^SELINUX=enforcing\>" \
      -e "^SELINUX=permissive\>")" ]
    then
      selinux="1"
    fi
  fi

  if [ -f /bin/star ]; then
    star="/bin/star"
  elif [ -f /usr/bin/star ]; then
    star="/usr/bin/star"
  fi

  local TODO=""  mm=0
  local IAHEAD="$IAHEAD / run_cpiostar"

  if [ "$use_type" = "star" ]; then
    if [ ! "$star" ]; then
      err "star is forced, but not installed"
    fi
  elif [ "$use_type" = "cpio" ]; then
    if [ "$selinux" ]; then
      warn "selinux is active; cpio is forced; using cpio; loosing infos"
    fi
  elif [ "$use_type" = "auto" ]; then
    use_type="cpio"
    if [ "$selinux" ]; then
      if [ "$star" ]; then
        use_type="star"
      else
        warn "selinux is active; star not installed; using cpio; loosing infos"
      fi
    fi
  else
    err "use_type=<$use_type> not known"
  fi

  for i in $RCPIO_EXCLUDE_DIRS ; do
     [ "$ext" ] && ext="$ext; s|\x00.${i}[^\x00]*||g" || ext="s|\x00${i}[^\x00]*||g"
  done

  let mm=$mm+1; eval local IGNORE${mm}=\"\"; eval local STDOUT${mm}=\"\"
  in_stdout $mm "^backup to .*"
  in_ignore $mm "^find: WARNING: Hard link count is wrong for ./proc: .*"
  in_stdout $mm "Permission denied$"
  in_stdout $mm "^find: \./proc/.*"
  in_stdout $mm "^cpio.*truncating inode number"

  in_stdout $mm "^star: .* unsupported file type 'socket'. Not dumped."
  in_stdout $mm "^star: .* blocks + .* bytes (total of .* bytes =.*)"
  in_stdout $mm "^star: Missing links .*, Name too long .*, File too big .*, Not dumped .*"
  in_stdout $mm "^star: Processed all possible files, despite earlier errors."
  TODO="$TODO \"run_cpiostar_kern $use_type\""

  [ "$interact" ] && interact="" || interact="-y"
  eval "interactive -h \"=== \$IAHEAD ===\" $interact -r $TODO"
}

#. /usr/share/bootcd/bootcd-run.lib
#RCPIO_EXCLUDE_DIRS=""
#IAHEAD="main"
#f=/tmp/run_cpiostar; rm -rf $f; mkdir -p $f/t; touch $f/t/"a a"
#run_cpiostar -i -d $f/t $f
#[ -f $f/cpio00 ] && (cat $f/cpio* |gzip -d -c | cpio -it )
#[ -f $f/star00 ] && (cat $f/star* |gzip -d -c | star -xattr -t -f - )
#run_cpiostar -d $f/t -u cpio $f
#[ -f $f/cpio00 ] && (cat $f/cpio* |gzip -d -c | cpio -it )
#[ -f $f/star00 ] && (cat $f/star* |gzip -d -c | star -xattr -t -f - )
#run_cpiostar -d $f/t -u star $f
#[ -f $f/cpio00 ] && (cat $f/cpio* |gzip -d -c | cpio -it )
#[ -f $f/star00 ] && (cat $f/star* |gzip -d -c | star -xattr -t -f - )