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\"`"
108 plog "-----------------------------------------------------------------"
109 plog "Backup for host $host"
110 plog "-----------------------------------------------------------------"
112 plog "Destination: $dst"
113 plog "Last: $current_dir"
116 perror "$dst already exists, skipping..." &&
119 perror "$host is down, skipping..." &&
122 extra_flags="--exclude-from=$exclude --delete-excluded"
124 extra_flags="$extra_flags --include-from=$include"
125 plog "Rotating backup..."
126 $run cp -al $V "$current_dir" "$dst" ||
128 plog "Running rsync..."
129 $run rsync $RSYNC_FLAGS $extra_flags $src "$dst/" ||
131 plog "Moving current..."
132 $run rm $V "$current_link" ||
134 $run ln -s $V "$date" "$current_link" ||
136 if [ $ret -ne $saved_ret ]
138 ERROR_HOSTS="$ERROR_HOSTS $host"
142 plog "========================================================================="
143 plog "Backup for $date finished at `date '+%Y-%m-%d %H:%M:%S'`"
144 plog "========================================================================="
148 pout "There were some errors when running the backup on: $ERROR_HOSTS"
150 pout "Please take a look at the log: $LOG_FILE"