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