I have a bunch of log files which are named according to their creation dates. For example; if my log file is created on 12 March 2018, the name of the logfile is log-2018-03-12.log
Here is what I want to do: From today's date, I want to check the name of my log files and zip the log files which are created in last 10 days.
Here is my code that zip all log files in a specific directory:
#!/bin/bash
# current time
now=$(date +"%F")
backupfile="backup-$now"
scripthome=/opt/MyStore/action_scripts/deneme/
tendaysbefore= date -d "$now - 10 days" '+%F'
for file in $scripthome;
do
find "$(basename "$file")" | zip -R $backupfile.zip "log-2*.log"
done
But I want to zip last 10 days log file, not all log files, and also I want to continue doing it for every 10 days after this. Also, after having zip file, I want to delete old log files. In other words, I am trying to write a log-backup script. Can you help me please?
Thank you very much!