b4f8c58bea31847dae357ed18ea1acf8328043c1
[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 if [ ! -d "$backupdir" ]
24 then
25    mkdir -p "$backupdir" || fatal "Can not make directory $backupdir"
26 fi
27
28 if [ ! -w "$backupdir" ]
29 then
30    fatal "Directory $backupdir is not writable"
31 fi
32
33 ## DO IT #################################################
34 #
35 # here we grab a list of the packages installed and removed.
36 #
37
38 case $compress in
39    "compress")
40       compress_option="-Z"
41       EXTENSION="tar.compress"
42       ;;
43    "gzip")
44       compress_option="-z"
45       EXTENSION="tgz"
46       ;;
47    "bzip")
48       compress_option="-j"
49       EXTENSION="tar.bz2"
50       ;;
51    "none")
52       compress_option=""
53       ;;
54    *)
55       warning "Unknown compress filter ($tar_compress)"
56       compress_option=""
57       EXTENSION="tgz"
58       ;;
59 esac
60
61 exclude_options=""
62 for i in $excludes
63 do
64    exclude_options="$exclude_options --exclude $i"
65 done
66
67 debug "Running backup: " $TAR -c -p -v $compress_option $exclude_options \
68    -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
69    $includes
70
71 $TAR -c -p -v $compress_option $exclude_options \
72    -f "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`".$EXTENSION" \
73    $includes \
74    > "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.list \
75    2> "$backupdir/$backupname-"`$DATE "+$DATEFORMAT"`.err
76
77 [ $? -ne 0 ] && fatal "Tar backup failed"
78
79
80