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
#!/bin/sh

###############################################################################
# This is the backup script the previous server monkey left for us. It is
# ghastly but hey, it works. Will be replaced with something better soon^Wsome 
# day.
#
# Update: even ghastlier than I'd thought !@#
# Mod: talks too much, tries to tar /proc and itself.
# - Removed -v.
# - Added exclusion list for /proc, sockets, etc.
#
# backupj depends on the weekday to run - if cron.daily is too late, the backup
# for friday will run early monday morning
#
# The tapes are 200 GB uncompressed, ~400G compressed. Compression is on.
#
# TYPICAL BACKUP TOTALS - for a good time pipe into gnuplot
#
# Date      Bytes    deltaBytes  
# 2006-04-02   26591498240 0        (25GiB, 15MiB/s)
# 2006-04-03   27029985280 +438487040  (26GiB, 15MiB/s)
# 2006-04-04   27699968000 +669982720  (26GiB, 14MiB/s)
# 2006-04-05   27625144320 -74823680   (26GiB, 14MiB/s)
# 2006-04-06   28117452800 +492308480  (27GiB, 14MiB/s)
#
# Delta was high in April because storebackup wasn't deleting old backups yet.
# They should start getting smaller after 2006-05-04 after the server will
# have been in production for a month.
#
# At that rate we'd have run out of *uncompressed* tape space by 2007-09-27.
#
# 2007-04-02   71014072320 (67GiB, 13MiB/s)
# 2007-04-03   70587596800 (66GiB, 13MiB/s)
# 2007-04-04   71197020160 (67GiB, 13MiB/s)
#
# Fortunately, growth has slowed down and compression seems to be working well.
#
# But more stuff is being stored on the server. Time for a cleanup?
# 2007-10-03  155686881280 (145GiB, 13MiB/s)
# 2007-10-05  156753694720 (146GiB, 13MiB/s)
#
#
# SEE ALSO
#
# /etc/storebackup.d/full, tar(1), mt(1)
#
# CHANGELOG
#
# 2005-11-29 GR Added --bzip2 - this morning's tape was full.
# 2005-12-20 GR Removed --bzip2 - Galileo overheating?
# 2006-03-18 GR Moving to 200GB tapes
# 2006-03-29 GR Only run during weekends
# 2006-03-29 GR Added real logging
# 2007-04-02 GR Added some TODOs, re-enabled logging.
# 2007-04-05 GR Updated usage statistics
#
# TODO
#
# Warn if there is no tape, with possible exception on holidays.
# Don't run on holidays
# Have a special cron entry and get out of cron.daily - don't run on weekends.
###############################################################################

#DEBUG="--totals" # Uncomment to get fancy statistics in the backup log.
OWNER="La Mexicaine de Perforation"
TAPE="/dev/st0"
COMPRESSION=2 # 0 is off, 2 is on, 1 is default

# Logs to syslog
log(){
   if [ -z "$2" ]; then # Is parameter #2 zero length?
      logger -it backup "$1"
   else
      logger -it backup "$1" "$2"
   fi
}

# Checks whether there is a tape in the drive.
checktape(){
   mt --file=$TAPE status &>/dev/null
   if [ $? -eq 2 ]; then
      log -s "No cartridge in tape drive!"
   fi
}

if [ `date +%u` -lt 6 ]; then # Don't run during weekends.
   checktape || exit 2
   mt --file=$TAPE datcompression $COMPRESSION &>/dev/null
   log "Starting backup"
   tar_result=$(tar $DEBUG \
    --create \
    --atime-preserve \
    --absolute-names \
    --label "$OWNER `date +%F`" \
    --exclude-from /etc/backup-exclude --file $TAPE / \
    && mt --file=$TAPE offline
   )
   if [ ! -z "$tar_result"]; then
      log -s $tar_result
   fi
   log "Ending backup"  
else
   log "No backup on `date +%A`, have a nice weekend!"
fi