4 # Default config values
12 # Don't actually do anything, just print the commands
15 # Force synchronization, even when the target already exist
18 # Log file (if empty, print to stdout/err)
21 # Where to find the configuration of the hosts to backup
22 CONFIG_PATH=/etc/bacap/hosts
24 # Name of the local host (so no ssh would be used with this host)
27 # Where to put the backups
30 # Date format used for backed up directories (passed to the date command)
33 # Ping remote hosts to check if they are up (set to 0 if your hosts don't
34 # reply to ICMP pings).
38 RSYNC_FLAGS="-aAXHx --numeric-ids --delete"
40 # rsync flags to use when in verbose mode
41 RSYNC_VERBOSE_FLAGS="-v --stats"
43 # rsync remote shell to use
44 RSYNC_RSH="ssh -c arcfour -o Compression=no -x"
48 SCRIPT_DIR=$(dirname `readlink -f $0`)
51 # Load configuration files
53 source "/etc/bacaprc" 2> /dev/null
54 source "/etc/bacap/bacaprc" 2> /dev/null
55 source "$SCRIPT_DIR/bacaprc" 2> /dev/null
56 test -n "$BACAPRC" && source "$BACAPRC"
66 RSYNC_FLAGS="$RSYNC_FLAGS $RSYNC_VERBOSE_FLAGS"
71 exec 1>>"$LOG_FILE" &&
88 ping -c1 "$1" > /dev/null 2>&1
91 date=`date "+$DATE_FMT"`
94 plog "========================================================================="
95 plog "Starting backup for $date at `date '+%Y-%m-%d %H:%M:%S'`"
96 plog "========================================================================="
98 for host_path in "$CONFIG_PATH"/*
101 # Load default config and override config if correspond
103 source "$host_path/bacaprc" 2>/dev/null
104 host=`basename "$host_path"`
105 host_backup_path="$BACKUP_PATH/$host"
106 dst="$BACKUP_PATH/$host/$date"
107 src=`cat "$host_path/paths"`
108 [ "$host" != "$LOCALHOST" ] &&
109 src=`awk "{print \"$host:\"\\$1}" "$host_path/paths"`
110 exclude="$host_path/excludes"
111 include="$host_path/includes"
112 current_link="$host_backup_path/current"
113 current_dir="$host_backup_path/`readlink \"$current_link\"`"
115 plog "-----------------------------------------------------------------"
116 plog "Backup for host $host"
117 plog "-----------------------------------------------------------------"
119 plog "Destination: $dst"
120 plog "Last: $current_dir"
122 [ -d "$dst" ] && [ "$FORCE_SYNC" -ne 1 ] &&
123 perror "$dst already exists, skipping..." &&
125 [ "$PING_CHECK" -eq 1 ] && ! ping_host $host &&
126 perror "$host is down, skipping..." &&
129 extra_flags="--exclude-from=$exclude --delete-excluded"
131 extra_flags="$extra_flags --include-from=$include"
132 plog "Running rsync..."
133 $run rsync $RSYNC_FLAGS $extra_flags \
134 --link-dest="$current_dir" $src "$dst/" ||
136 plog "Moving current..."
137 $run rm $V "$current_link" ||
139 $run ln -s $V "$date" "$current_link" ||
141 if [ $ret -ne $saved_ret ]
143 ERROR_HOSTS="$ERROR_HOSTS $host"
147 plog "========================================================================="
148 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
149 plog "========================================================================="
153 pout "There were some errors when running the backup on: $ERROR_HOSTS"
155 pout "Please take a look at the log: $LOG_FILE"