We are uploading our SQL Server backups to the OCI object storage because of DR reasons. Whenever a new backup is uploaded the oldest one is supposed to be deleted.
Is it possilbe to somehow just delete the oldest backup using CLI?
Using life cycle policies or retention rules is not an option since the oldest backup is only supposed to be deleted once a new file is uploaded if nothing is uploaded nothing is supposed to be deleted. I know there is the bulk-delete command but I don't know if you can somehow limit it to just deleting the oldest file.
oci os object list --all --fields name,timeCreated --bucket-name <backup_bucket>
will list the name and the creation time of all your backups.
I would then pipe that with jq to easily find the oldest file.
oci os object delete --force --bucket-name <backup_bucket> --object-name <older_backup_name>
will delete that backup without prompting for a confirmation thanks to the force parameter (useful if used in a script)