linux - improving my backup bash script -
hello keep log files under /opt/project/logs/ , want daily copy these /opt/bkp compressing them.
for have written , works well:
#!/bin/bash getdate(){ date --date="$1 days ago" "+%y_%m_%d" } rm -rf "/opt/bkp/logs/myapp_log_"$(getdate 365).gz ; /bin/cat /opt/project/logs/myapp.log | gzip > /opt/bkp/logs/myapp_log_`date +%y_%m_%d`.gz ; echo "" > /opt/project/logs/myapp.log ; however not functional or general, have several applications saving files names ie app1.log app2.log under same /opt/project/logs/ folder. how can make "function" script reads each file under /opt/project/logs/ directory , taking backup of each file ends .log extension?
you use logrotate(8) tool came distro. :) manpage has example looks close need:
/var/log/news/* { monthly rotate 2 olddir /var/log/news/old missingok postrotate kill -hup `cat /var/run/inn.pid` endscript nocompress } well, not monthly bit, or restarting inn :) hope idea add new config file /etc/logrotate.d/ , not worry again. :)
Comments
Post a Comment