remove_nonfullbackups.sh 692 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #! /bin/sh
  2. FTP_SERVER=backup.serverkompetenz.de
  3. BAK_PATH=backup/full
  4. BAK=$1
  5. if [ -z ${BAK} ]; then
  6. echo "USAGE: `basename $0` BAK_DIR" >&2
  7. exit 1
  8. fi
  9. set -A FILES `/usr/local/bin/curl -s -n -l "ftp://${FTP_SERVER}/${BAK_PATH}/${BAK}/" \
  10. | grep -v '^\.' | grep -v '\.gz$' | grep -v '\-0$'`
  11. let RESULT=$?
  12. if [ ${RESULT} != 0 ]; then
  13. echo "curl returned ${RESULT}"
  14. exit 2
  15. fi
  16. let IDX=0
  17. (
  18. cat <<-EOF
  19. open ${FTP_SERVER}
  20. cd "${BAK_PATH}/${BAK}/"
  21. prompt
  22. EOF
  23. while [ ${IDX} -lt ${#FILES[@]} ]; do
  24. FNAME=${FILES[IDX]}
  25. echo "del ${FNAME}"
  26. IDX=$((IDX + 1))
  27. done
  28. echo 'close'
  29. ) | ftp
  30. let RESULT=$?
  31. if [ ${RESULT} != 0 ]; then
  32. echo "ftp returned ${RESULT}"
  33. exit 3
  34. fi
  35. exit 0