Updated update-system
[clearscm.git] / bin / backup
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         $RCSfile: backup,v $
5 # Revision:     $Revision: 1.7 $
6 # Description:  This script backs up the system in a consistent way
7 # Author:       Andrew@DeFaria.com
8 # Created:      Tue Jul 27 15:00:11 PDT 2004
9 # Modified:     $Date: 2011/05/26 06:17:20 $
10 # Language:     Bash
11 #
12 # (c) Copyright 2000-2005, ClearSCM, Inc., all rights reserved.
13 #
14 ################################################################################
15 # Full Backup
16 backup=/sbin/dump
17 dumppath=/backup
18 filesystems="sda1 sdb1"
19 compression=9
20
21 if [ -f /etc/dump.excludes ]; then
22   excludes="-E /etc/dump.excludes"
23 else
24   excludes=""
25 fi
26
27 if [ $(id -u) -ne 0 ]; then
28   echo "You must be root to backup"
29   exit 1
30 fi
31
32 function usage {
33   type="$1"
34
35   echo "Usage: backup <full | incremental>"
36   exit 1
37 } # usage
38
39 type="$1"
40 host=$(hostname)
41
42 if [ "$type" = "full" ]; then
43   rm -f $dumppath/$host.*.$type.backup
44   rm -f $dumppath/$host.*.$type.backup.log
45   rm -f $dumppath/$host.*.$type.list  
46   level=0
47 elif [ "$type" = "incremental" ]; then
48   level=1
49 else
50   usage $type
51 fi
52
53 for fs in $filesystems; do
54   log=$dumppath/$host.$fs.$type.backup.log
55   $backup -$level\
56     -A $dumppath/$host.$fs.$type.list\
57     -f $dumppath/$host.$fs.$type.backup\
58     -z$compression\
59     $excludes\
60     -u /dev/$fs > $log 2>&1 
61 done