aboutsummaryrefslogtreecommitdiff
path: root/backup.in
blob: 477b839d0b4a1c0d998e25a8abc33874cd71343d (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
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
134
135
136
137
138
139
140
141
142
143
144
#! /bin/sh
# This file is part of BEAM
# Copyright (C) 2012-2014 Sergey Poznyakoff
#
# BEAM is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# BEAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BEAM.  If not, see <http://www.gnu.org/licenses/>.

libdir=@LIBDIR@/beam
set -e
. $libdir/common.sh
set +e
ts=`date +%Y%m%d`;
week=`date +%U`

if [ "$1" = "--wtf" ]; then
    wtf $(basename $0) create a backup
    exit 0
fi

load_config
taroptions="-c -Hpax $backup_tar_options $backup_rsh_command"

###########################################################
# Global variables
###########################################################

# Set it to "-v" to make script verbose
if [ -n "$backup_verbose" ]; then 
    verbose=-v
else
    verbose=
fi
# Set it to "echo" to initiate dry-run mode.
unset dry_run

# Number of tar errors detected during the run
tarerror=0

level=0
round=0

###########################################################
# Utility functions
###########################################################

help() {
    cat <<EOF
usage: $0 [OPTIONS]
makes incremental backup of that system

OPTIONS:

  -v, --verbose        increase verbosity
  -l, --logfile FILE   log to FILE (default $backup_logfile)
  -n, --dry-run        do nothing, print what would have been done
  -N, --no-logfile     log to stderr
  -L, --level N        create incremental dump level N
  -R, --round N        mark archives with incremental round N
  --week N             force using week number N instead of the current one
  -h, --help           produce this help list

Report bugs to <@PACKAGE_BUGREPORT@>
EOF
    exit 0
}

###########################################################
# Main
###########################################################

while [ $# -ne 0 ]
do
    case $1 in
	-v|--verbose) verbose="$verbose -v";;
	-l|--logfile) shift; backup_logfile=$1;;
	-n|--dry-run) dry_run=echo; backup_logfile=;;
	-N|--no-logfile) backup_logfile=;;
	-h|--help) help;;
	-V|--version) print_version;;
	-L|--level) shift; level=$1;;
	-R|--round) shift; round=$1;;
	--week) shift; week=$1;;
	*) echo >&2 "$0: unrecognized option $1"; exit 1;;
    esac
    shift
done

backup() {
    logit "started"
    
    runhook prologue_hook
    trap "runhook epilogue_hook" EXIT INT QUIT TERM
    
    if test -n "$backup_retain_interval" &&
	test $backup_retain_interval -gt 0; then
	@LIBEXECDIR@/beam-cleaner --retain $backup_retain_interval $verbose \
                ${dry_run+--dry-run} --suffix $backup_suffix $backup_archive_dir
	@LIBEXECDIR@/beam-cleaner --retain $backup_retain_interval $verbose \
                ${dry_run+--dry-run} --suffix .db $backup_snapshot_dir
    fi

    for item in $backup_items
    do
	eval type=\$${item}_type
	${type}_backup $item
    done
    
    trap - EXIT INT QUIT TERM
    runhook epilogue_hook
    
    logit "finished"
}

umask ${backup_umask:-077}
prologue_hook="beam_lock $prologue_hook"

if [ -n "$backup_logfile" ]; then
    runhook openlog_hook
    exec >>$backup_logfile
    exec 2>&1
fi
if [ -z "$backup_notify_email" ]; then
    backup
else
    report=$backup_snapshot_dir/report.$$
    touch $report
    backup 2>&1 | tee $report
    mail_report $report
    rm $report
fi


# finis coronat opus

Return to:

Send suggestions and report system problems to the System administrator.