This script can automatically backup the remote server using rsync. It will detect the space left on the server and delete old backup tar(s) if the free space remaining is smaller than 50G. Also, the script compresses the backup for two days ago at the beginning and saves them into tar.gz, in order to save spaces.
The standard output of rsync is discarded and only errors are printed. Feel free to modify the script for your own purpose. The necessary settings can be set at the beginning of this script.
Adding this script to crontab by executing crontab -e
, we can automatically backup the server without exceeding the storage limitation and store the log file.
0 0,12 * * * sh [script_path] >> [log_path]/$(date +"\%Y\%m\%d_\%H\%M\%S").log 2>&1