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)
30 # Ping remote hosts to check if they are up (set to 0 if your hosts don't
31 # reply to ICMP pings).
35 RSYNC_FLAGS="-aAXHx --numeric-ids --delete"
37 # rsync flags to use when in verbose mode
38 RSYNC_VERBOSE_FLAGS="-v --stats"
40 # rsync remote shell to use
41 RSYNC_RSH="ssh -c arcfour -o Compression=no -x"
45 SCRIPT_DIR=$(dirname `readlink -f $0`)
48 # Load configuration files
50 source "/etc/bacaprc" 2> /dev/null
51 source "/etc/bacap/bacaprc" 2> /dev/null
52 source "$SCRIPT_DIR/bacaprc" 2> /dev/null
53 test -n "$BACAPRC" && source "$BACAPRC"
63 RSYNC_FLAGS="$RSYNC_FLAGS $RSYNC_VERBOSE_FLAGS"
68 exec 1>>"$LOG_FILE" &&
85 ping -c1 "$1" > /dev/null 2>&1
88 date=`date "+$DATE_FMT"`
91 plog "========================================================================="
92 plog "Starting backup for $date at `date '+%Y-%m-%d %H:%M:%S'`"
93 plog "========================================================================="
95 for host_path in "$CONFIG_PATH"/*
98 # Load default config and override config if correspond
100 source "$host_path/bacaprc" 2>/dev/null
101 host=`basename "$host_path"`
102 host_backup_path="$BACKUP_PATH/$host"
103 dst="$BACKUP_PATH/$host/$date"
104 src=`cat "$host_path/paths"`
105 [ "$host" != "$LOCALHOST" ] &&
106 src=`awk "{print \"$host:\"\\$1}" "$host_path/paths"`
107 exclude="$host_path/excludes"
108 include="$host_path/includes"
109 current_link="$host_backup_path/current"
110 current_dir="$host_backup_path/`readlink \"$current_link\"`"
112 plog "-----------------------------------------------------------------"
113 plog "Backup for host $host"
114 plog "-----------------------------------------------------------------"
116 plog "Destination: $dst"
117 plog "Last: $current_dir"
120 perror "$dst already exists, skipping..." &&
122 [ "$PING_CHECK" -eq 1 ] && ! ping_host $host &&
123 perror "$host is down, skipping..." &&
126 extra_flags="--exclude-from=$exclude --delete-excluded"
128 extra_flags="$extra_flags --include-from=$include"
129 plog "Rotating backup..."
130 $run cp -al $V "$current_dir" "$dst" ||
132 plog "Running rsync..."
133 $run rsync $RSYNC_FLAGS $extra_flags $src "$dst/" ||
135 plog "Moving current..."
136 $run rm $V "$current_link" ||
138 $run ln -s $V "$date" "$current_link" ||
140 if [ $ret -ne $saved_ret ]
142 ERROR_HOSTS="$ERROR_HOSTS $host"
146 plog "========================================================================="
147 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
148 plog "========================================================================="
152 pout "There were some errors when running the backup on: $ERROR_HOSTS"
154 pout "Please take a look at the log: $LOG_FILE"