The system manages disk space on a server where multiple services store video, audio, and archive files. Large files that have not been modified for a set period are encrypted and moved to Yandex.Disk, while a text note is left in the local directory to facilitate retrieval.
The cleanup process runs daily at 04:00 Moscow time, targeting files larger than 50 MB that have remained unchanged for three days. If available disk space drops below 25 GiB, the system performs an emergency cleanup with a one-day threshold every three hours.
Between November 20 and November 24, the utility cleared 56 GB of data from a 150 GB disk. The system uses AES256 encryption via GPG for all files moved to cloud storage and verifies integrity by comparing MD5 hashes and file sizes via the Yandex.Disk REST API.
To prevent security risks associated with root access, the script verifies paths for symbolic links and executes file operations as the specific user who owns the directory. The system uses the SUDO_UID environment variable to ensure services can only retrieve their own files.
The utility is integrated into the main loop of a mirroring service to prevent data loss. If the process is interrupted, the system ensures that files are not incorrectly marked as deleted, maintaining consistency between the local server and the remote backup.



