runner-export.sh.jinja2 1.94 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
srv_directory={{ directory['srv'] }}

11 12 13 14 15
sync_element () {
  path=$1
  backup_path=$2
  shift 2
  element_list=$*
16 17 18

  # Concatenate the exclude file of each partition of webrunner
  # to create a global exclude file.
19
  exclude_content="instance/supervisord.socket"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  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

36 37
  for element in $element_list
  do
38
    echo "Changing current directory to $path."
39 40
    cd $path;
    if [ -f $element ] || [ -d $element ]; then
41 42
       echo "Running {{ rsync_binary }} -rlptgov --safe-links --exclude-from=$srv_directory/exporter.exclude --delete --delete-excluded $element  $backup_path"
       {{ rsync_binary }} -rlptgov --safe-links --exclude-from=$srv_directory/exporter.exclude --delete --delete-excluded $element  $backup_path;
43 44 45
    fi
  done
}
46
sync_element $srv_directory/runner {{ directory['backup'] }}/runner/ instance project proxy.db
47 48 49 50 51 52 53
# 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
54

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