aboutsummaryrefslogtreecommitdiff
path: root/lib/backup/common.in
blob: ab8020406da09561205a3e4550e9b93cfb71ee32 (plain)
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
#! /bin/bash

# Force C locale
LC_ALL=C
export LC_ALL

prologue_hook=
epilogue_hook=

# User configuration variables
backup_tar_options=
backup_suffix=
backup_archive_dir=
backup_snapshot_dir=
backup_verbose=
backup_logfile="/var/log/backup"

error() {
  echo >&2 $0: $*
}

logit() {
  echo `date`: $*
}

abend() {
  ec=$1
  shift
  error $@
  exit $ec
}

tarcode() {
  case $1 in
  0) echo "`date`: success";;
  1) echo "`date`: some files changed while being archived";;
  2) echo "`date`: fatal error occurred, but trying to continue anyway"
     tarerror=$((tarerror + 1));;
  *) echo "`date`: unexpected error code $1"
     tarerror=$((tarerror + 1));
  esac
}

load_config() {
  local delayed_exit  
  
  test -z "$BACKUP_CONFIG" && BACKUP_CONFIG=@SYSCONFDIR@/backup.conf
  if [ -r $BACKUP_CONFIG ]; then
    . $BACKUP_CONFIG
  else
    abend 1 "configuration file $BACKUP_CONFIG does not exist or is unreadable"
  fi
  
  if [ -z "$backup_items" ]; then
    abend 1 "backup_items not specified"
  fi

  delayed_exit=
  loaded_types=
  for item in $backup_items
  do
    eval type=\$${item}_type
    if [ -z "$type" ]; then
      error "${item}_type not set"
      delayed_exit=1
      continue
    fi
  
    if echo "$loaded_types" | grep -wq $type; then
      :
    elif [ -x $libdir/${type}.sh ]; then
      . $libdir/${type}.sh || delayed_exit=1
      loaded_types="$loaded_files
$type"
    else
      error "$libdir/${type}.sh not found"
      delayed_exit=1 
    fi

    ${type}_check $item || delayed_exit=1
  done

  test -n "$delayed_exit" && abend 1 "aborting"

  tar_suffix=${backup_suffix:-.tar}
}

Return to:

Send suggestions and report system problems to the System administrator.