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.

37 lines
878 B

  1. #!/usr/bin/env sh
  2. if [ $# != 3 ]; then
  3. echo "usage: $0 <cache-fs> <base-pool> <percentage>"
  4. exit 1
  5. fi
  6. CACHEFS="${1}"
  7. BASEPOOL="${2}"
  8. PERCENTAGE=${3}
  9. set -o errexit
  10. while [ $(df "${CACHE}" | tail -n1 | awk '{print $5}' | cut -d'%' -f1) -gt ${PERCENTAGE} ]
  11. do
  12. # Find the file with the oldest access time
  13. FILE=$(find "${CACHE}" -type f -printf '%A@ %P\n' | \
  14. sort | \
  15. head -n 1 | \
  16. cut -d' ' -f2-)
  17. # If no file found, exit
  18. test -n "${FILE}" || exit 0
  19. # Move file
  20. rsync \
  21. --archive \
  22. --acls \
  23. --xattrs \
  24. --atimes \
  25. --hard-links \
  26. --one-file-system \
  27. --quiet \
  28. --preallocate \
  29. --remove-source-files \
  30. --relative \
  31. --log-file=/tmp/mergerfs-cache-rsync.log \
  32. "${CACHE}/./${FILE}" \
  33. "${BACKING}/"
  34. done