#611 [dist-git] add script to remove old logs
Merged 5 years ago by praiskup. Opened 5 years ago by dturecek.
copr/ dturecek/copr remove-old-distgit-logs  into  master

@@ -0,0 +1,3 @@ 

+ #!/usr/bin/sh

+ 

+ runuser -c 'find /var/lib/copr-dist-git/per-task-logs -name *.log -mtime +30 -delete' - copr-dist-git

file modified
+6 -1
@@ -32,6 +32,7 @@ 

  Requires: python3-munch

  Requires: findutils

  Requires: (copr-selinux if selinux-policy-targeted)

+ Requires: crontabs

  

  Recommends: python3-copr

  
@@ -69,6 +70,9 @@ 

  install -d %{buildroot}%{_var}/log/copr-dist-git

  install -d %{buildroot}%{_sharedstatedir}/copr-dist-git

  install -d %{buildroot}%{_bindir}/

+ install -d %{buildroot}%{_sysconfdir}/cron.monthly

+ 

+ install -p -m 755 conf/cron.monthly/copr-dist-git %{buildroot}%{_sysconfdir}/cron.monthly/copr-dist-git

  

  cp -a dist_git/* %{buildroot}%{_datadir}/copr/dist_git

  cp -a conf/copr-dist-git.conf.example %{buildroot}%{_sysconfdir}/copr/copr-dist-git.conf
@@ -100,11 +104,12 @@ 

  %license LICENSE

  

  %{_bindir}/*

- %dir %{_datadir}/copr 

+ %dir %{_datadir}/copr

  %{_datadir}/copr/*

  %dir %{_sysconfdir}/copr

  %config(noreplace) %attr(0640, root, copr-dist-git) %{_sysconfdir}/copr/copr-dist-git.conf

  %config(noreplace) %attr(0644, root, root) %{_sysconfdir}/httpd/conf.d/copr-dist-git.conf

+ %config(noreplace) %attr(0755, root, root) %{_sysconfdir}/cron.monthly/copr-dist-git

  

  %dir %attr(0755, copr-dist-git, copr-dist-git) %{_sharedstatedir}/copr-dist-git/

  

no initial comment

You probably wanted to use last_change here.

Can you match .log using regular expression: /.log$/ ?

From numerical POV it would be better to have
if ( (time.time() - os.stat(filepath).st_mtime ) / (3600*24) ) > days
to get away from rounding error when rounding to integer. But I reckon that it is not a real issue here, a few days does not matter here.

Please don't use a regular expression for this. file.endswith(".log") is much cleaner.

I know we already discussed this, but still... don't we want to call this instead?
subprocess.call(['find', logdir, '-name', '*.log', '-mtime', '+{}'.format(days), '-delete'

I mean s/call/check_call/ (or something like that..).

rebased onto 41ee60976f3d8f9823ae5c592a2a8e6c4556d72f

5 years ago

I have moved the find ... -delete command to a monthly cron job instead.

This implies we should have Requires: crontabs.

rebased onto 78f4866

5 years ago

This implies we should have Requires: crontabs.

Done

Pull-Request has been merged by praiskup

5 years ago