template-backup-script.sh.in 1.48 KB
Newer Older
1 2 3 4 5 6
#!${dash-output:dash}

# trap "echo Backing up failed for $${:hostname}" ERR

export HOME=$${directory:home}

7 8
# Clean status file (no history needed)
${coreutils-output:rm} -f $${:status_log}
9
${coreutils-output:rm} -f $${:statistic_log}
10 11

# Inform about beginning of backup
12
${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log}, $${:hostname} backup running" >> $${:status_log}
13
${coreutils-output:echo} "Available only if backup succeed." >> $${:statistic_log}
14 15

# set -e
16 17 18 19 20
cd $${:datadirectory}
${rdiff-backup-output:rdiff-backup} \
  $${:exclude_string} \
  --include='$${:include}' \
  --exclude='**' \
21
  --remote-schema '${openssh-output:ssh} -6 -q -T -y -o "StrictHostKeyChecking no" -i $${:sshkey} -p $${:connection_port} %s $${:remote_schema}' \
22 23
  $${:connection}::/ ./

24 25 26
RESULT=$?
 
# Inform about backup status
27
${coreutils-output:rm} -f $${:status_log}
28
if [ $RESULT -eq 0 ]
29
then
30 31
  ${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log},$${:hostname} backup success" >> $${:status_log}
  ${coreutils-output:rm} -f $${:statistic_log}
32
  ${findutils-output:find} rdiff-backup-data/ -maxdepth 1 -name "session_statistic*" | ${coreutils-output:sort} | ${coreutils-output:tail} -n 1 | ${findutils-output:xargs} ${rdiff-backup-output:rdiff-backup} --calculate-average >> $${:statistic_log}
33
else
34
  ${coreutils-output:echo} "`${coreutils-output:date} -u`,$${:statistic_log},$${:hostname} backup failed" >> $${:status_log}
35 36
fi

37 38
# python scripts/verify_with_sudo.py ./ $${:connection}:/