This would help any Sysad who wants to retain or keep the latest backups or files automatically using a script.
Sample Codes Below:
#!/bin/bash # # This script retains 2 files # Created by Burnz Barbosa # # LOG_FILE="/var/log/retain_script.log" cd /mnt/backups/full num_files=`ls | wc -l` rm `ls -tp | grep -v "/$" | awk '{ if (NR > 2) print; }'` num_files2=`ls | wc -l` /bin/echo "[$(date)]You have the latest $num_files2 retained in backup files " >> $LOG_FILE
Script Explanations:
The script is to keep the latest 2 files under /mnt/backups/full
1. We declare the log file at /var/log/ named as retain_script.log
2. Go to the backup directory, lets assumed /mnt/backups/full
3. Then we remove the count of oldest files and retain the latest 2
4. We ask to display the counts or number of files that it contains
5. We write a log with a date telling how many backups have retained and put it in the logfile
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-37138722-1']); _gaq.push(['_trackPageview']);
(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();