backup.sh 609 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. WORKDIR=/var/lib/influxdb/backup
  3. # check if we are the user influxdb
  4. if [ ! "$(whoami)" == "influxdb" ] ; then
  5. echo "This script must run as user influxdb"
  6. exit 1
  7. fi
  8. # Create workdir if it does not exist
  9. [ ! -d ${WORKDIR} ] && mkdir ${WORKDIR}
  10. pushd ${WORKDIR} > /dev/null
  11. if [ -d $(date -I) ] ; then
  12. echo "Backupdirectory for today already exists. I refuse to do anything"
  13. exit 1
  14. fi
  15. echo "Backup"
  16. influxd backup -portable $(date -I)
  17. echo "Backup finished"
  18. ehco "--------------------------------------------"
  19. echo "Cleanup"
  20. find ${WORKDIR} -ctime +2 -delete
  21. popd > /dev/null