This was my inefficient approach until I realized I should be using
find ... -exec. Anyone finding this question via search engines should use Nikolaidis Fotis' answer.
Original answer for historical purposes...
I am using this in my cron job and it works well...
/usr/bin/python -c "from subprocess import call;from datetime import datetime;import os;today=datetime.today();dir='/var/log/net/';[call('cp -p %s /mnt/backup/' % (dir+file), shell=True) for file in os.listdir(dir) if (today - datetime.fromtimestamp(os.stat(dir+file).st_mtime)).days==29]"
The reason I look for a file modification time of 29 days (
st_mtime) is because that is how old the modification time is before
logrotate deletes files from the
If you don't like enormous one-liners above, you could save this as a file and run it from
from subprocess import call
from datetime import datetime
longterm = '/mnt/backup/'
[call('cp -p %s %s' % (dir+file, longterm), shell=True) \
for file in os.listdir(dir) if (today - \
I am using
cp -p to ensure I save file modification times so I can use a similar script to delete them from long-term storage after a couple of years.