If I copy files with backup (cp --backup=numbered), the old file is renamed to something like oldfile.ext.1. I get my old files. Can this be limited to a certain number of old files, for example 30? I don't want to have keep more than that...
If I copy files with backup (cp --backup=numbered), the old file is renamed to something like oldfile.ext.1. I get my old files. Can this be limited to a certain number of old files, for example 30? I don't want to have keep more than that...
2 Comments
INeedMana@lemmy.world · 1 pts · 1y
With
cp, I don't think so. But I guess you could try using logrotate for thatMoLoPoLY@discuss.tchncs.de · 1 pts · 1y
Unfortunately, logrotate does not work the way I would like it to. I have now created a bash script, which hopefully does what it is supposed to do:
Invoked in the respective directory, all *.db files are read into an array, as there can be different DBs per user. The array is then processed in a loop. First, the backup files for the respective DB are read into the array again, sorted by age. This array is then processed and all files whose index +1 is greater than keepCount are removed. This means that the oldest files are always removed and only those that are defined in the keepCount are kept.
Its a little bit more complicated, but it seems to do the job.