V
V
Viktor Taran2017-09-03 18:22:29
bash
Viktor Taran, 2017-09-03 18:22:29

How to remove the directory with the name of the latest year?

The task is to delete the oldest year, when the backup disk is filled with more than 90%
of the existing directories

/var/backup/site/2011
/var/backup/site/2012
/var/backup/site/2013
...

Created by a cycle when backing up
Need to delete 2011
if the answer is 1
test $(df -h |grep "/var/backup" | awk {'print $5'} | sed 's/\%//g') \< 90;

Not a time interval!!! As in different years the different sizes of backups.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Mukovoz, 2017-09-04
@shambler81

If the /var/backup/site/ folder contains only folders with years and you need to delete exactly by the folder name, and not by the date of modification, then this option is quite suitable.
If you are afraid to execute it right away, try what the command will give you
. will be removed. But be careful with writing scripts that automatically delete backups, you will lose the logic and all backups are deleted)
I wrote a script that deletes the oldest backup every day before a new one is created, but if in your case you delete the whole year, is it not easier to delete it manually. Once a year, you can get dirty) Another thing is if this is a daily process, as in the case in which I cited)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question