You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

start.sh 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #! /bin/bash
  2. # If first arg is bash, we'll just execute directly
  3. if [ "$1" == "bash" ]; then
  4. exec "$@"
  5. exit 0
  6. fi
  7. # If no env variable set, get from command line
  8. if [ "$OPT_ARGUMENTS" == "" ]; then
  9. export OPT_ARGUMENTS="$@"
  10. fi
  11. # If key id is provied add arg
  12. if [ -e "$GPG_KEY_ID" ]; then
  13. export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
  14. fi
  15. # If set to restore on start, restore if the data volume is empty
  16. if [ "$RESTORE_ON_EMPTY_START" == "true" -a -z "$(ls -A $PATH_TO_BACKUP)" ]; then
  17. /cron-exec.sh /restore.sh
  18. fi
  19. # Unless explicitly skipping, take a backup on startup
  20. if [ "$SKIP_ON_START" != "true" ]; then
  21. /cron-exec.sh /backup.sh
  22. fi
  23. if [ -n "$CRON_SCHEDULE" ]; then
  24. # Export the environment to a file so it can be loaded from cron
  25. env | sed 's/^\(.*\)=\(.*\)$/export \1="\2"/g' > /env.sh
  26. # Remove some vars we don't want to keep
  27. sed -i '/\(HOSTNAME\|affinity\|SHLVL\|PWD\)/d' /env.sh
  28. # Use bash for cron
  29. echo "SHELL=/bin/bash" > /crontab.conf
  30. # Schedule the backups
  31. echo "$CRON_SCHEDULE /cron-exec.sh /backup.sh" >> /crontab.conf
  32. echo "Backups scheduled as $CRON_SCHEDULE"
  33. if [ -n "$FULL_CRON_SCHEDULE" ]; then
  34. echo "$FULL_CRON_SCHEDULE /cron-exec.sh /backup.sh full" >> /crontab.conf
  35. echo "Full backup scheduled as $VERIFY_CRON_SCHEDULE"
  36. fi
  37. if [ -n "$VERIFY_CRON_SCHEDULE" ]; then
  38. echo "$VERIFY_CRON_SCHEDULE /cron-exec.sh /verify.sh" >> /crontab.conf
  39. echo "Verify scheduled as $VERIFY_CRON_SCHEDULE"
  40. fi
  41. # Add to crontab
  42. crontab /crontab.conf
  43. echo "Starting duplicity cron..."
  44. cron
  45. touch /cron.log /root/duplicity.log
  46. tail -f /cron.log /root/duplicity.log
  47. fi