Bash or PHP script to delete old backup files
$30-50 USD
Paid on delivery
I need a bash or PHP script that:
- Will run daily via Cron
- Will receive 3 parameters: Directory, MaxDays, MaxDaysLastFile
- Will delete files in Directory that are older then MaxDays
- But will not delete the last file for a particular "name" (see bellow), unless it's older than MaxDaysLastFile
The backup directory will contain several files with the format "[url removed, login to view]".
These backup files are being generated periodically for active customers.
The customer name is identified by the "name" part in the file name.
If the client is suspended or inactive, no new backup file will be generated.
So over time, I'll keep only one file for the suspended clients (the newest), up to MaxDaysLastFile days.
The goal is to periodically delete the oldest backups keeping at least one backup for supended clients.
For example, I'll keep daily backups for two weeks (MaxDays = 14), and I'll keep at least one backup for suspended clients for six months (MaxDaysLastFile = 180).
Here is a sample of file names in such directory:
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
[url removed, login to view]
For this example, these files should be deleted:
[url removed, login to view] (older than 14 days, and there are other newer files for the same name)
[url removed, login to view] (last file for "altatecbr", but it's older than 180 days)
[url removed, login to view] (older than 14 days, and there are other newer files for the same name)
If you wish, you can use the file date to date operations instead of the date in the file name (your choice).
I need the script to be delivered until march 9.
Project ID: #2718339