f75df22e7a124586ed88ffd69f8e91cba6024481
[matthijs/upstream/backupninja.git] / handlers / tar.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
3 #
4 # tar handler script for backupninja
5
6 getconf backupname      `hostname --fqdn`
7 getconf backupdir       /var/backups/`hostname --fqdn`
8 getconf compress        bzip
9 getconf includes        "/etc /home /usr/local"
10 getconf excludes        "/tmp /proc /dev /sys /net /misc /media /srv /selinux"
11
12 getconf TAR             `which tar`
13 getconf EXTENSION       tar
14 getconf DATE            `which date`
15 getconf DATEFORMAT      "%Y.%m.%d-%H%M"
16
17 # See if vservers are configured
18 if [ "$vservers" = "yes" ]
19 then
20    warning "vservers enabled, but tar does not support it!"
21 fi
22
23 function make_backup () {
24    if [ ! -d "$backupdir" ]
25    then
26       mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
27    fi
28
29    if [ ! -w "$backupdir" ]
30    then
31       fatal "Directory $backupdir is not writable"
32    fi
33
34    ## DO IT #################################################
35    #
36    # here we grab a list of the packages installed and removed.
37    #
38
39    case $compress in
40       "compress")
41          compress_option="-Z"
42          EXTENSION="tar.compress"
43          ;;
44       "gzip")
45          compress_option="-z"
46          EXTENSION="tgz"
47          ;;
48       "bzip")
49          compress_option="-j"
50          EXTENSION="tar.bz2"
51          ;;
52       "none")
53          compress_option=""
54          ;;
55       *)
56          warning "Unknown compress filter ($tar_compress)"
57          compress_option=""
58          EXTENSION="tgz"
59          ;;
60    esac
61
62    exclude_options=""
63    for i in $excludes
64    do
65       exclude_options="$exclude_options --exclude $i"
66    done
67
68    debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
69       -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
70       $includes
71
72    $TAR -c -p -v $compress_option $exclude_options \
73       -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
74       $includes \
75       > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
76       2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
77
78    [ $? -ne 0 ] && fatal "Tar backup failed"
79
80 }
81
82 make_backup