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"/*
93 # Load default config and override config if correspond
95 source "$host_path/bacaprc" 2>/dev/null
96 host=`basename "$host_path"`
97 host_backup_path="$BACKUP_PATH/$host"
98 dst="$BACKUP_PATH/$host/$date"
99 src=`cat "$host_path/paths"`
100 [ "$host" != "$LOCALHOST" ] &&
101 src=`awk "{print \"$host:\"\\$1}" "$host_path/paths"`
102 exclude="$host_path/excludes"
103 current_link="$host_backup_path/current"
104 current_dir="$host_backup_path/`readlink \"$current_link\"`"
106 plog "-----------------------------------------------------------------"
107 plog "Backup for host $host"
108 plog "-----------------------------------------------------------------"
110 plog "Destination: $dst"
111 plog "Last: $current_dir"
114 perror "$dst already exists, skipping..." &&
117 perror "$host is down, skipping..." &&
120 exclude_flags=" --exclude-from=$exclude --delete-excluded"
121 plog "Rotating backup..."
122 $run cp -al $V "$current_dir" "$dst" ||
124 plog "Running rsync..."
125 $run rsync $RSYNC_FLAGS $exclude_flags $src "$dst/" ||
127 plog "Moving current..."
128 $run rm $V "$current_link" ||
130 $run ln -s $V "$date" "$current_link" ||
134 plog "========================================================================="
135 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
136 plog "========================================================================="
140 pout 'There were some errors when running the backup.'
142 pout "Please take a look at the log: $LOG_FILE"