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"
41 SCRIPT_DIR=$(dirname `readlink -f $0`)
44 # Load configuration files
46 source "/etc/bacaprc" 2> /dev/null
47 source "/etc/bacap/bacaprc" 2> /dev/null
48 source "$SCRIPT_DIR/bacaprc" 2> /dev/null
49 test -n "$BACAPRC" && source "$BACAPRC"
59 RSYNC_FLAGS="$RSYNC_FLAGS $RSYNC_VERBOSE_FLAGS"
64 exec 1>>"$LOG_FILE" &&
81 ping -c1 "$1" > /dev/null 2>&1
84 date=`date "+$DATE_FMT"`
87 plog "========================================================================="
88 plog "Starting backup for $date at `date '+%Y-%m-%d %H:%M:%S'`"
89 plog "========================================================================="
91 for host_path in "$CONFIG_PATH"/*
94 # Load default config and override config if correspond
96 source "$host_path/bacaprc" 2>/dev/null
97 host=`basename "$host_path"`
98 host_backup_path="$BACKUP_PATH/$host"
99 dst="$BACKUP_PATH/$host/$date"
100 src=`cat "$host_path/paths"`
101 [ "$host" != "$LOCALHOST" ] &&
102 src=`awk "{print \"$host:\"\\$1}" "$host_path/paths"`
103 exclude="$host_path/excludes"
104 include="$host_path/includes"
105 current_link="$host_backup_path/current"
106 current_dir="$host_backup_path/`readlink \"$current_link\"`"
109 plog "-----------------------------------------------------------------"
110 plog "Backup for host $host"
111 plog "-----------------------------------------------------------------"
113 plog "Destination: $dst"
114 plog "Last: $current_dir"
117 perror "$dst already exists, skipping..." &&
120 perror "$host is down, skipping..." &&
123 extra_flags="--exclude-from=$exclude --delete-excluded"
125 extra_flags="$extra_flags --include-from=$include"
126 plog "Rotating backup..."
127 $run cp -al $V "$current_dir" "$dst" ||
129 plog "Running rsync..."
130 $run rsync $RSYNC_FLAGS $extra_flags $src "$dst/" ||
132 plog "Moving current..."
133 $run rm $V "$current_link" ||
135 $run ln -s $V "$date" "$current_link" ||
137 if [ $ret -ne $saved_ret ]
139 ERROR_HOSTS="$ERROR_HOSTS $host"
143 plog "========================================================================="
144 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
145 plog "========================================================================="
149 pout "There were some errors when running the backup on: $ERROR_HOSTS"
151 pout "Please take a look at the log: $LOG_FILE"