disk-maintenance 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # search and destroy garbage files in root
  3. find / -type f -iname "thumbs.db" -exec rm {} \; &
  4. find / -type f -iname ".ds_store" -exec rm {} \; &
  5. find / -type f -name '._*' -exec rm -rf {} \; &
  6. # functions for asynchronous operations
  7. cleanup_ext4() {
  8. fstrim "$1"
  9. e4defrag "$1"
  10. }
  11. cleanup_btrfs() {
  12. fstrim "$1"
  13. btrfs balance start -dusage=1 "$1"
  14. btrfs balance start -musage=1 "$1"
  15. btrfs balance start -dusage=5 "$1"
  16. btrfs balance start -musage=5 "$1"
  17. btrfs balance start -dusage=10 "$1"
  18. btrfs balance start -musage=10 "$1"
  19. btrfs balance start -dusage=25 "$1"
  20. btrfs balance start -musage=25 "$1"
  21. btrfs balance start -dusage=50 "$1"
  22. btrfs balance start -musage=50 "$1"
  23. btrfs scrub start -qdB "$1"
  24. btrfs filesystem defragment -rfclzo "$1"
  25. }
  26. # defragment and fstrim ext4 weekly
  27. for filesystem in $(mount -t ext4 | awk '{print $3}'); do
  28. cleanup_ext4 "$filesystem" &
  29. done
  30. # defragment and rebalance btrfs weekly
  31. for filesystem in $(mount -t btrfs | awk '{print $3}'); do
  32. cleanup_btrfs "$filesystem" &
  33. done
  34. # wait for jobs to complete
  35. for j in $(jobs -p); do
  36. wait $j
  37. done