Hello:
I have a script that gets the ACLs of the /home
directory and its contents with getfacl
and writes them to a file. The script is run by a cron job and I don't want it to rewrite or append to an already existing file. The point of backing permissions up is because I may need to restore them. But I don't want to store every single created file either.
The files don't need to have a specific naming convention. In fact, I took advantage of this: I decided to name the files after the date they were created:
#!/bin/sh
readonly file="$(date +'%Y-%m-%d')"
getfacl -pR /home > "/var/acl_backups/$file"
This has the advantage that the most recent files are alphabetically greater than older ones, so I thought of putting them in the positional parameters and delete the one I didn't want to preserve. For example, if I wanted to have a maximum of 7 files in the /var/acl_backups
directory:
#!/bin/sh
LC_COLLATE=C set -- [[:digit:]][[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]
if [ $# -ge 7 ]
then
rm -- "$7"
fi
readonly file="$(date +'%Y-%m-%d')"
getfacl -pR /home > "/var/acl_backups/$file"
Changing the locale of LC_COLLATE
may be unnecessary, but I decided to change it just to be sure it sorts numbers from 0 to 9.
My question is: is this a reliable way to rotate files? I thought of using logrotate
was well, but as far as I know, it would mean that every file would have the same name except for a number at the end. If I ever need to restore them with setfacl
having the date in their names is very convenient.
Thanks in advance.