4 # Default config values
12 # Don't actually do anything, just print the commands
15 # Log file (if empty, print to stdout/err)
18 # Where to find the configuration of the hosts to backup
19 CONFIG_PATH=/etc/bacap/hosts
21 # Name of the local host (so no ssh would be used with this host)
24 # Where to put the backups
27 # Date format used for backed up directories (passed to the date command)
31 RSYNC_FLAGS="-aAXHx --numeric-ids --delete"
33 # rsync flags to use when in verbose mode
34 RSYNC_VERBOSE_FLAGS="-v --stats"
36 # rsync remote shell to use
37 RSYNC_RSH="ssh -c arcfour -o Compression=no -x"
42 # Load configuration files
43 source "/etc/bacaprc" 2> /dev/null
44 source "/etc/bacap/bacaprc" 2> /dev/null
45 source `dirname \`readlink -f "$0"\``/bacaprc 2> /dev/null
46 test -n "$1" && source "$1"
55 RSYNC_FLAGS="$RSYNC_FLAGS $RSYNC_VERBOSE_FLAGS"
60 exec 1>>"$LOG_FILE" &&
77 ping -c1 "$1" > /dev/null 2>&1
80 date=`date "+$DATE_FMT"`
83 plog "========================================================================="
84 plog "Starting backup for $date at `date '+%Y-%m-%d %H:%M:%S'`"
85 plog "========================================================================="
87 for host_path in "$CONFIG_PATH"/*
89 host=`basename "$host_path"`
90 host_backup_path="$BACKUP_PATH/$host"
91 dst="$BACKUP_PATH/$host/$date"
92 src=`cat "$host_path/paths"`
93 [ "$host" != "$LOCALHOST" ] &&
94 src=`awk "{print \"$host:\"\\$1}" "$host_path/paths"`
95 exclude="$host_path/excludes"
96 current_link="$host_backup_path/current"
97 current_dir="$host_backup_path/`readlink \"$current_link\"`"
99 plog "-----------------------------------------------------------------"
100 plog "Backup for host $host"
101 plog "-----------------------------------------------------------------"
103 plog "Destination: $dst"
104 plog "Last: $current_dir"
107 perror "$dst already exists, skipping..." &&
110 perror "$host is down, skipping..." &&
113 exclude_flags=" --exclude-from=$exclude --delete-excluded"
114 plog "Rotating backup..."
115 $run cp -al $V "$current_dir" "$dst" ||
117 plog "Running rsync..."
118 $run rsync $RSYNC_FLAGS $exclude_flags $src "$dst/" ||
120 plog "Moving current..."
121 $run rm $V "$current_link" ||
123 $run ln -s $V "$date" "$current_link" ||
127 plog "========================================================================="
128 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
129 plog "========================================================================="
133 pout 'There were some errors when running the backup.'
135 pout "Please take a look at the log: $LOG_FILE"