runner-export.sh.jinja2 1.96 KB
Newer Older
1
#!{{ shell_binary }}
2 3
LC_ALL=C
export LC_ALL
4
umask 077
5

6 7 8
# Exit on any error, to prevent inconsistent backup
set -e

9 10 11 12 13 14
# Redirect output to log
exec > >(tee -ai {{ output_log_file }})
exec 2>&1

echo -e "\n\n$0 run at : $(date)"

15 16
srv_directory={{ directory['srv'] }}

17 18 19 20 21
sync_element () {
  path=$1
  backup_path=$2
  shift 2
  element_list=$*
22 23 24

  # Concatenate the exclude file of each partition of webrunner
  # to create a global exclude file.
25
  exclude_content="instance/supervisord.socket"
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  for partition in $srv_directory/runner/instance/slappart*
  do
    exclude_file="$partition/srv/exporter.exclude"
    if [ -e "$exclude_file" ]; then
      partition_exclude_content_relative=$(cat "$exclude_file")
      # For every line of the local exclude file, add the absolute path
      for line in "$partition_exclude_content_relative"
      do
        if [ ! -z "$line" ]; then
          exclude_content="$exclude_content\ninstance/$(basename $partition)/$line"
       fi
      done
    fi
  done
  echo "$exclude_content" > $srv_directory/exporter.exclude

42 43
  for element in $element_list
  do
44
    echo "Changing current directory to $path."
45 46
    cd $path;
    if [ -f $element ] || [ -d $element ]; then
47 48 49
       command="{{ rsync_binary }} -rlptgov --stats --safe-links --exclude-from=$srv_directory/exporter.exclude --delete --delete-excluded $element  $backup_path"
       echo "Running : $command"
       $command
50 51 52
    fi
  done
}
53
sync_element $srv_directory/runner {{ directory['backup'] }}/runner/ instance project proxy.db
54 55 56 57 58 59 60
# We sync .* appart
date +%s -u > {{ directory['etc'] }}/.resilient-timestamp
cp -r {{ directory['etc'] }}/.??* {{ directory['backup'] }}/etc/
sync_element {{ directory['etc'] }}  {{ directory['backup'] }}/etc/ config.json ssh
if [ -d {{ directory['backup'] }}/runner/software ]; then
  rm {{ directory['backup'] }}/runner/software/*
fi
61

62
cd {{ directory['backup'] }} && find -type f ! -name backup.signature -print0 | xargs -P4 -0 sha256sum | LC_ALL=C sort -k 66 > backup.signature